mysql中为字段追加属性的方法
1.首先,新建一个数据库,并在数据库中新建一个test表
create database Data;use Data;
create table test;
2.test表新建好后,查看表结构
desc test;
结构如下:
+----------+------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | |
| username | varchar(15) | NO | | NULL | |
+----------+------------------+------+-----+---------+----------------+
3.在表为ID字段追加一个AUTO_INCREMENT属性
alter table test MODIFY id INT UNSIGNED AUTO_INCREMENT;
4.AUTO_INCREMENT属性添加后,继续查看表结构
desc test;
结构如下:
+----------+------------------+------+-----+---------+----------------+| Field | Type | Null | Key | Default | Extra |
+----------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| username | varchar(15) | NO | | NULL | |
+----------+------------------+------+-----+---------+----------------+
可以看到ID字段的AUTO_INCREMENT属性以添加。