2015-04-22 62 views
0

我有幾個值,和從1 auto_incremented主鍵的簡單表:INSERT AUTO_INCREMENT值

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使用下一個值。

+0

不要在語句中提供自動增量字段名稱或值。假裝它不在那裏,數據庫會照顧它。 –

+0

你不想插入自動增量值 – Cherry

+0

INSERT INTO test1(aweek,ranking,studentid)VALUES('2015-04-20',1,1012) – Cherry

回答

1

當您將列聲明爲自動增量時,當您將其他值插入到表中時,Db將採用它。

INSERT INTO test1 (aweek,ranking,studentid) VALUES 
('2015-04-20',1,1012) 
+0

謝謝 - 我以爲我曾嘗試過,但沒有。 – user3741598