◆ 테이블 이름 변경
mysql> alter table 현재_테이블_이름 rename 새로운_테이블_이름;
mysql> show tables;
+----------------+
| Tables_in_oops |
+----------------+
| old_table |
+----------------+
1 row in set (0.00 sec)
mysql>
mysql> alter table old_table rename new_table;
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> show tables;
+----------------+
| Tables_in_oops |
+----------------+
| new_table |
+----------------+
1 row in set (0.00 sec)
mysql>
◆ 테이블 컬럼 이름 변경
mysql> alter table 테이블_이름 change 현재_컬럼_이름 새로운_컬럼_이름 타입;
mysql> desc new_table;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| name | varchar(50) | YES | | NULL | |
| descr | varchar(128) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql> alter table new_table change name title varchar(16);
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc new_table;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| title | varchar(16) | YES | | NULL | |
| descr | varchar(128) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql>
◆ 테이블 컬럼 타입 변경
mysql> alter table 테이블_이름 modify 컬럼명 변경_타입;
mysql> desc new_table;
+-------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| title | varchar(16) | YES | | NULL | |
| descr | varchar(128) | YES | | NULL | |
+-------+--------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
mysql>
mysql> alter table new_table modify title varchar(50);
Query OK, 0 rows affected (0.00 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>
출처 : http://iamoops.tistory.com/277
'database, query' 카테고리의 다른 글
UNIX_TIMESTAMP 변환하기 (0) | 2014.10.13 |
---|---|
페이징시 유효한 FOUND_ROWS(); (0) | 2014.10.09 |
mysqldump(백업) (0) | 2014.10.08 |
테이블 구조 복사 및 내용 복사 (0) | 2014.10.06 |
테이블 컬럼 추가, 변경, 삭제 (0) | 2014.09.27 |