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 ?
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.
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) .
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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With