티스토리 뷰
컬럼 추가
alter table 테이블_이름 add 컬럼_이름 타입 ;
mysql> desc new_table;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| title | varchar(50) | YES | | NULL | |
| descr | varchar(128) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql>
mysql>
mysql> alter table new_table add num int(4) not null default 0;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc new_table;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| title | varchar(50) | YES | | NULL | |
| descr | varchar(128) | YES | | NULL | |
| num | int(4) | NO | | 0 | |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
컬럼 삭제
mysql> desc new_table;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| title | varchar(50) | YES | | NULL | |
| descr | varchar(128) | YES | | NULL | |
| num | int(4) | NO | | 0 | |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql>
mysql> alter table new_table drop num;
Query OK, 0 rows affected (0.01 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc new_table;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| title | varchar(50) | YES | | NULL | |
| descr | varchar(128) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql>
'개발 > DB' 카테고리의 다른 글
[oracle] 명령어 링크 (0) | 2013.06.24 |
---|---|
[mysql] 컬럼 추가에 대한 고찰... (0) | 2013.04.30 |
[mysql] 테이블 이름 변경 / 테이블 컬럼 이름,타입 변경 (0) | 2013.03.21 |
[mysql] index 추가/제거 (0) | 2013.03.08 |
[mysql] database 백업/복구 (0) | 2013.01.29 |
댓글
최근에 올라온 글
최근에 달린 댓글
글 보관함
- Total
- Today
- Yesterday