SQL Server > Table

Set primary key to existing column in SQL Server

How to set a column as primary key to the existing database table in SQL Server?


To set existing column as primary key, run following sql script in the Query window.

Alter table PersonalDetails
ADD Primary Key (AutoId)

In the above case, we are assuming that AutoId is a existing column in the PersonalDetails table.

Here AutoId column will be set as primary key to the PersonalDetails table.

 Views: 23069 | Post Order: 21



Write for us






Hosting Recommendations