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屬性以添加。