数据库的基本操作之删除(单/多)列

来源:互联网 发布:剑网南风捏脸米苏数据 编辑:程序博客网 时间:2024/05/23 21:53
删除单列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: 0mysql> select * from users1;+----+----------+------+| id | username | pid |+----+----------+------+| 3 | wuxie | 2 || 4 | Tom | 1 |+----+----------+------+2 rows in set (0.00 sec)

0 0
原创粉丝点击