You can create an auto-increment or auto-decrement table in SQL Server, which will automatically add value for every new row by incrementing or decrementing the value of last row. These type of Column are known as Identity Column. These kind of columns are generally required where you want to set some kind of ID for any thing like Employee ID in Employee table, Session ID in Session table, Item ID in Items table, etc..
You can’t modify a column to set it as Identity column of an existing Table. You can only set it while creating new table.
- While creating new table, select the column whom you want to make as Identity column.
- In the Column Properties, click on the “+” icon for “Identity Specifications”.
- Change the value of “(Is Identity)” from “No” to “Yes”.
- Type the value for “Identity Increment” field there, by which you want to increment value in every row of that column. This is generally 1 because you just want every new value for that column to be 1 greater that the previous row.
- If you want to set the starting value to be other that 1, you can then specify that in “Identity Seed” field. I am specifying it to be 1000 instead of just 1.
Incoming search terms:
- auto increment field in sql server (60)