首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

mysql自动增长列解决方案

2012-02-05 
mysql自动增长列我把mysql的主键设置为自动增长了create table test(id int auto_increment not null,name

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;

热点排行