Add column as primary key with auto-increment in existing database table

Updated on     Kisan Patel

To create a new column in the existing database table as primary key and auto increment, execute following script in the query window against the database.

Alter table Users
Add UserId int NOT NULL IDENTITY (1, 1) Primary key

This adds a new column as UserId with auto increment value and set this column as Primary key of the table.

SQL Server

Leave a Reply