How to Add a Primary Key MS-sql Server 2008

How to add Primary key to th existing column in the MS-sql Server 2008
nrajasekhar7Asked:
Who is Participating?
 
LowfatspreadConnect With a Mentor Commented:
does the table already have a primary key?

what is the clustering index for the table?
are there additional indexes on the table?

basically

alter table youtablename
drop primary key

go

alter table yourtablename
add primary key (column1,column2,...)


0
 
OP_ZaharinCommented:
- the following link provide a further explanation on creating primary key on existing table. the syntax is as follows:
http://sqlserverplanet.com/sql/sql-server-add-primary-key/

ALTER TABLE tablename ADD CONSTRAINT primarykeyname_PK PRIMARY KEY (column1);


0
 
GSGDBACommented:
alter table TableName add constraint New_primary_key primary key (NewCol)
0
 
Racim BOUDJAKDJIDatabase Architect - Dba - Data ScientistCommented:
Post the script for the table you want to set a primary key onto.  
0
 
nrajasekhar7Author Commented:
Thanks you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.