简体   繁体   中英

INSERT auto_increment value

I have a simple table with a few values and a primary key that is auto_incremented from 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;

If I were able to I could INSERT INTO test1 (NULL,1012,1,'2015-04-20') , but the data comes in a different order so I tried INSERT INTO test1 (acounter,aweek,ranking,studentid) VALUES (NULL,'2015-04-20',1,1012) - receive an error that the primary key cannot be NULL. I don't want it to be - I expect the auto_increment to use the next value.

When you declared a column as auto increment ,Db will take of it as you insert the other values to the table.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM