1つのカラムの削除
1 |
ALTER TABLE [テーブル名] DROP COLUMN [カラム名]; |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
mysql> describe test; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | name | varchar(20) | YES | | NULL | | | age | int | YES | | NULL | | | address | varchar(100) | YES | | NULL | | | phone | varchar(15) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+ 4 rows in set (0.00 sec) mysql> alter table test drop column age; Query OK, 0 rows affected (0.03 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe test; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | name | varchar(20) | YES | | NULL | | | address | varchar(100) | YES | | NULL | | | phone | varchar(15) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+ 3 rows in set (0.00 sec) |
複数のカラムの削除
1 2 3 4 |
ALTER TABLE [テーブル名] DROP COLUMN [カラム名1], DROP COLUMN [カラム名2], ..... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
mysql> describe test; +---------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+-------+ | name | varchar(20) | YES | | NULL | | | age | int | YES | | NULL | | | address | varchar(100) | YES | | NULL | | | phone | varchar(15) | YES | | NULL | | +---------+--------------+------+-----+---------+-------+ 4 rows in set (0.01 sec) mysql> alter table test drop column age, drop column address; Query OK, 0 rows affected (0.02 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> describe test; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | name | varchar(20) | YES | | NULL | | | phone | varchar(15) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) |