请问下面俩个个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))
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))
create table tab_01(
id int auto_increment not null,
test varchar(10),
key(id)
)
结帖率:0%
当您的问题得到解答后请及时结贴.
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html
http://topic.csdn.net/u/20100428/09/BC9E0908-F250-42A6-8765-B50A82FE186A.html
http://topic.csdn.net/u/20100626/09/f35a4763-4b59-49c3-8061-d48fdbc29561.html8、如何给分和结贴?
http://bbs.csdn.net/help#post_dispose
create table a2(id int auto_increment,name text,index(id));这样添加后就能够成功创建数据表了//因为字段id中使用了auto_increment属性,所以要创建这个字段的索引。至于索引的类型,在这就不作讲解了