• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 474
  • Last Modified:

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
0
nrajasekhar7
Asked:
nrajasekhar7
1 Solution
 
LowfatspreadCommented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now