SQL Server > Table

Set auto-increment column in SQL Server

How to specify auto-increment column in the database while creating a new table in SQL Server?

Auto-increment column is very useful if we want a unique key for each record in the database table. This is generally treated as primary key and used to select, update, and delete records into the database table.

To specify an auto-increment column in the database table, the column name must be of Integer type (Int, BigInt etc.).

Select the column by clicking on the column and then see the Column Properties panel below it.

Go to Identity Specifications and explore it. Make (Is Identity) row as Yes and by default Identity Increment row and Identity Seed row become 1. In case we want to automatically increase the value of this column by 2 (like 1, 3, 5, 7 etc.) then change the value of Identity Seed to 2.

After setting this, save it by clicking the Save icon from top-left.


Please note that in SQL Server Management Studio Express, the auto-increment column can only be created at the time of creating a fresh table. Alter table, doesn’t provide option to add a new column with auto-increment facility.

 Views: 2097 | Post Order: 17

Write for us