Mysql增加表字段

版权声明:如若转载,请联系作者。 https://blog.csdn.net/liu16659/article/details/83188151

Mysql 增加表字段

mysql增加表字段语句如下:

alter table orders add column name varchar(20);
  • 示例:
mysql> desc orders;
+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| shipaddress | int(20)     | YES  | MUL | NULL    |                |
| shipcity    | varchar(20) | YES  |     | NULL    |                |
+-------------+-------------+------+-----+---------+----------------+
2 rows in set (0.02 sec)

执行sql语句:

mysql> alter table orders add column id int auto_increment primary key after shipcity;
Query OK, 0 rows affected (0.44 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table orders add column name varchar(20);
Query OK, 0 rows affected (0.34 sec)
Records: 0  Duplicates: 0  Warnings: 0
mysql> desc orders;
+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| shipaddress | int(20)     | YES  | MUL | NULL    |                |
| shipcity    | varchar(20) | YES  |     | NULL    |                |
| id          | int(11)     | NO   | PRI | NULL    | auto_increment |
| name        | varchar(20) | YES  |     | NULL    |                |
+-------------+-------------+------+-----+---------+----------------+
4 rows in set (0.02 sec)

猜你喜欢

转载自blog.csdn.net/liu16659/article/details/83188151