[英]INSERT auto_increment value
我有一個簡單的表,其中包含一些值和一個從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使用下一個值。
當您將列聲明為自動增量時,Db將在您將其他值插入表中時采用它。
INSERT INTO test1 (aweek,ranking,studentid) VALUES
('2015-04-20',1,1012)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.