首页 > 代码库 > 数据库的基本操作之多列添加
数据库的基本操作之多列添加
添加多列
ALTER TABLE tbl_name (ADD col_name1 column_defination1, ADD col_name2 column_defination2, ...)
注意:添加单列的时候可以指明位置关系,添加多列的时候不可以
如下
执行多列添加之前
mysql> select * from users1;
+----+----------+------+------+
| id | username | pid | age |
+----+----------+------+------+
| 3 | wuxie | 2 | 10 |
| 4 | Tom | 1 | 10 |
+----+----------+------+------+
2 rows in set (0.00 sec)
多列添加语句
mysql> alter table users1 add sex enum(‘1‘, ‘2‘, ‘3‘) default ‘3‘,add address varchar(30) not null;
Query OK, 0 rows affected (0.93 sec)
Records: 0 Duplicates: 0 Warnings: 0
多列添加以后
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)
数据库的基本操作之多列添加