Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
327 views
in Technique[技术] by (71.8m points)

sql - How to insert new row to database with AUTO_INCREMENT column without specifying column names?

I have a table with the following columns:

  • id - INT UNSIGNED AUTO_INCREMENT
  • name - VARCHAR(20)
  • group - VARCHAR(20)

I know that I can add a row like this:

INSERT INTO table_name (name, group) VALUES ('my name', 'my group')

I wonder if there is a way to add a row without specifying the column names, like when there is no AUTO_INCREMENT column ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

For some databases, you can just explicitly insert a NULL into the auto_increment column:

INSERT INTO table_name VALUES (NULL, 'my name', 'my group')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...