日期:2014-05-16  浏览次数:20826 次

mysql自动增长列
我把mysql的主键设置为自动增长了
create table test
(
  id int auto_increment not null,
  name varchar(100) null,
  primary key(id)
)
我插入一条数据
insert into test values('yangxun')
这样不行
非要给id传一个值 insert into test values(1,'yangxun');
id是自动增长为什么还非的要赋值!

------解决方案--------------------


SQL code
insert into test(name) values('yangxun');

------解决方案--------------------


SQL语法就是这样,否则SQL怎么知道你的是给哪一列的?

== 思想重于技巧 ==
------解决方案--------------------
也可以 insert into test values(null,'yangxun'); 

不用理会第一列的值就行了。

------解决方案--------------------
试试这样行不行,行的话告诉我一下。
create table test 

id int auto_increment not null, 
name varchar(100) null, 
primary key(id) 
)ENGINE=MyISAM;