티스토리 뷰

MySQL

[MySQL] 테이블 수정

Gayeong's 2022. 4. 14. 18:44

테이블 수정

필드 추가하기

ALTER TABLE 테이블명 ADD 추가할 필드명 AFTER 필드명 위치;
 

필드 수정하기

ALTER TABLE 테이블명 MODIFY 수정할 필드명;
mysql> ALTER TABLE myData MODIFY youGender int(20);
Query OK, 10 rows affected (0.04 sec)
Records: 10  Duplicates: 0  Warnings: 0
mysql> desc myData;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| myMemberID | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| youEmail   | varchar(40)      | NO   |     | NULL    |                |
| youName    | varchar(12)      | NO   |     | NULL    |                |
| youPass    | varchar(20)      | NO   |     | NULL    |                |
| youBirth   | varchar(12)      | NO   |     | NULL    |                |
| youAge     | varchar(12)      | NO   |     | NULL    |                |
| youGender  | int(20)          | YES  |     | NULL    |                |
| regTime    | int(11)          | NO   |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)

필드 삭제하기

ALTER TABLE 테이블명 DROP 삭제할 필드명
ALTER TABLE myData DROP youGender;
Query OK, 0 rows affected (0.08 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> desc myData;
+------------+------------------+------+-----+---------+----------------+
| Field      | Type             | Null | Key | Default | Extra          |
+------------+------------------+------+-----+---------+----------------+
| myMemberID | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
| youEmail   | varchar(40)      | NO   |     | NULL    |                |
| youName    | varchar(12)      | NO   |     | NULL    |                |
| youPass    | varchar(20)      | NO   |     | NULL    |                |
| youBirth   | varchar(12)      | NO   |     | NULL    |                |
| youAge     | varchar(12)      | NO   |     | NULL    |                |
| regTime    | int(11)          | NO   |     | NULL    |                |
+------------+------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
댓글
© 2018 webstoryboy