SQL Server > Table

Auto-increment to existing table in SQL Server

How to add a new column in the existing database table as Auto Increment column in the SQL Server?


Adding a new column as auto increment to the existing database table is not possible through the SQL Server Management studio (SSMS), so we do it by SQL Script. Open a new query window by clicking on the New Query icon from top left and run following command

Alter table PersonalDetails
Add AutoId int NOT NULL IDENTITY

This adds AutoId column to the PersonalDetails table with auto – increment type so that entering new record into this table automatically increase the value of the AutoId column.

 Views: 5276 | Post Order: 19



Write for us