gpt4 book ai didi

mysql - 插入自动增量值

转载 作者:行者123 更新时间:2023-11-29 12:15:59 25 4
gpt4 key购买 nike

我有一个简单的表,其中包含一些值和一个从 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)

关于mysql - 插入自动增量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29802143/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com