zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

Mysql增加表字段

mysql 增加 表字
2023-09-14 09:13:14 时间

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)