INSERT auto_increment值

时间:2015-04-22 15:26:06

标签: mysql

我有一个带有一些值的简单表和一个从1开始自动增加的主键:

create table test1 (acounter int not null primary key, studentid int not null, 
ranking int not null, aweek date not null);

alter table test1 auto_increment=1;

如果我能够INSERT INTO test1 (NULL,1012,1,'2015-04-20'),但数据的顺序不同,所以我尝试INSERT INTO test1 (acounter,aweek,ranking,studentid) VALUES (NULL,'2015-04-20',1,1012) - 收到主键不能为NULL的错误。我不希望它 - 我希望auto_increment使用下一个值。

1 个答案:

答案 0 :(得分:1)

当您将列声明为自动增量时,Db将在您将其他值插入表格时将其取出。

INSERT INTO test1 (aweek,ranking,studentid) VALUES
 ('2015-04-20',1,1012)
相关问题