删除单列
ALTER TABLE tbl_name DROP col_name;
例如:
删除之前
mysql> select * from users1;
+----+----------+------+------+------+---------+
| id | username | pid | age | sex | address |
+----+----------+------+------+------+---------+
| 3 | wuxie | 2 | 10 | 3 | |
| 4 | Tom | 1 | 10 | 3 | |
+----+----------+------+------+------+---------+
2 rows in set (0.00 sec)
删除单列
mysql> alter table users1 drop address;
Query OK, 0 rows affected (0.96 sec)
Records: 0 Duplicates: 0 Warnings: 0
删除之后的结果
mysql> select * from users1;
+----+----------+------+------+------+
| id | username | pid | age | sex |
+----+----------+------+------+------+
| 3 | wuxie | 2 | 10 | 3 |
| 4 | Tom | 1 | 10 | 3 |
+----+----------+------+------+------+
2 rows in set (0.01 sec)
删除多列
ALTER TABLE tbl_name DROP col_name, DROP col_name;
删除sex,和age列
mysql> alter table users1 drop sex, drop age;
Query OK, 0 rows affected (0.93 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> select * from users1;
+----+----------+------+
| id | username | pid |
+----+----------+------+
| 3 | wuxie | 2 |
| 4 | Tom | 1 |
+----+----------+------+
2 rows in set (0.00 sec)
数据库的基本操作之删除(单/多)列
最新推荐文章于 2024-07-15 19:19:56 发布