作者:飞跃星空2502906253 | 来源:互联网 | 2020-08-24 19:31
mysql增加两个字段:mysql>createtableid_name(idint,namevarchar(20));QueryOK,0rowsaffected(0.13sec)...
mysql如何增加字段?
mysql增加两个字段:
mysql> create table id_name(id int,name varchar(20));
Query OK, 0 rows affected (0.13 sec)
mysql> alter table id_name add age int,add address varchar(11);
Query OK, 0 rows affected (0.13 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc id_name;
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
| address | varchar(11) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
mysql增加一个字段:
alter table user add COLUMN new1 VARCHAR(20) DEFAULT NULL; //增加一个字段,默认为空
alter table user add COLUMN new2 VARCHAR(20) NOT NULL; //增加一个字段,默认不能为空
以上就是mysql如何增加字段?的详细内容,更多请关注 第一PHP社区 其它相关文章!