mysql自动增长(auto_increment)约束问题
Mr.王征 2017-09-27 09:08:40 请问下面俩个个sql语句那个正确,为什么?
1,mysql> create table a1(id int primary key auto_increment,name text);
2,mysql> create table a2(id int auto_increment,name text);
当我的想要自动增长的字段添加主键约束之后,则可以编译成功
mysql> create table a1(id int primary key auto_increment,name text);
Query OK, 0 rows affected (0.01 sec)
当该字段没有添加主键约束,直接自增长则会出现错误
mysql> create table a2(id int auto_increment,name text);
ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key(想要自动增长必须给他一个键(key))