开发者

How to work with auto incrementing columns in mySQL

开发者 https://www.devze.com 2023-03-16 02:37 出处:网络
how would开发者_开发知识库 I use the insert into syntax with mysql columns that are auto incrementing?

how would开发者_开发知识库 I use the insert into syntax with mysql columns that are auto incrementing?

for example:

INSERT INTO table (auto, firstname, lastname) VALUES ('Dan','Davidson')

would the above code work and fill in the columns firstname and lastname while having auto auto-increment?


You don't need to list the auto-incrementing column in the field list, it will auto-increment regardless:

INSERT INTO table (firstname, lastname) VALUES('Dan', 'Davidson')


No, the code would not work. The auto-increment column should not be inserted to as the value is dynamically generated. Doing the following:

INSERT INTO table (firstname, lastname) VALUES ("fName", "lName")

Will automatically assign a vlue to the "auto" field.


You can just leave that field null.

INSERT INTO table (auto, firstname, lastname) VALUES (null, 'Dan','Davidson')

or just leave the auto incrementing field out.

INSERT INTO table (firstname, lastname) VALUES ('Dan','Davidson')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号