Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 764
Misha Moroshko Avatar asked Aug 16 '10 13:08

Misha Moroshko


People also ask

When inserting data in a table do you always have to specify a list of all column names you are inserting values for?

Because the values are typed in the same order in which the columns appear in the table, it is not necessary to type the column names. As a side note, if you want to insert values into specific columns only, specify only the column names you want to insert values into.

How do I create a row auto increment in SQL?

The MS SQL Server uses the IDENTITY keyword to perform an auto-increment feature. In the example above, the starting value for IDENTITY is 1, and it will increment by 1 for each new record. Tip: To specify that the "Personid" column should start at value 10 and increment by 5, change it to IDENTITY(10,5) .

How can change auto increment column in SQL Server?

ALTER TABLE Inventory MODIFY COLUMN item_number INT AUTO_INCREMENT=50; After running this code, future item IDs will start at an item_number of 50 and increment by 1. To change the starting increment value and increment in SQL Server, set your non-default values during table creation.


1 Answers

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') 
like image 154
Ike Walker Avatar answered Oct 14 '22 23:10

Ike Walker