티스토리 뷰
테이블 수정
필드 추가하기
ALTER TABLE 테이블명 ADD 추가할 필드명 AFTER 필드명 위치;
ALTER TABLE myMember ADD youGender enum('m', 'w', 'x') default 'x' comment "남성은 m, 여성은 w" AFTER youBirth;
desc mymember;
+------------+-------------------+------+-----+---------+----------------+
| 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 | |
| youGender | enum('m','w','x') | YES | | x | |
| regTime | int(11) | NO | | NULL | |
+------------+-------------------+------+-----+---------+----------------+
7 rows in set (0.00 sec)
필드 수정하기
ALTER TABLE 테이블명 MODIFY 수정할 필드명
mysql> desc mymember2;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| myMemberID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| youName | varchar(12) | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
mysql> ALTER TABLE mymember2 MODIFY youName int(20);
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc mymember2;
+------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+------------+------------------+------+-----+---------+----------------+
| myMemberID | int(10) unsigned | NO | PRI | NULL | auto_increment |
| youName | int(20) | YES | | NULL | |
+------------+------------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
필드 삭제하기
ALTER TABLE 테이블명 drop 삭제할 필드명
mysql> ALTER TABLE mymember2 drop youGender;
Query OK, 0 rows affected (0.04 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc mymember2;
+------------+------------------+------+-----+---------+----------------+
| 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 | |
| youAddress | varchar(30) | NO | | NULL | |
| youAge | int(2) | NO | | NULL | |
| regTime | int(11) | NO | | NULL | |
+------------+------------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)
'MYSQL' 카테고리의 다른 글
MYSQL - 테이블 합치기(JOIN) (0) | 2022.04.17 |
---|---|
MYSQL - 테이블 데이터 (0) | 2022.04.17 |
MYSQL - 테이블 (0) | 2022.04.17 |
MYSQL - 데이터베이스 (0) | 2022.04.17 |
MYSQL - MYSQL과 설치 (0) | 2022.04.15 |
댓글
© 2018 webstoryboy