views:

24

answers:

2

Hi

I am using SQL Server 2005. When I try to set the primary key constraint for a column in the alter statement. it committed error. i used this following query,

alter table "table name" modify(field__name integer(size) primary key);

can u say what the error actually.. expect ur valuable answer.. if u know other methods send me the query..

A: 

Plese ensure the column data has unique values before adding a primary key constraint to that column

also the syntax seems to be wrong in your statement. For SQL server, ALTER syntax is given below -

http://msdn.microsoft.com/en-us/library/ms190273.aspx

Sachin Shanbhag
A: 

I think it's

ALTER TABLE [table name] ADD PRIMARY KEY (column1, column2)

etc. if the columns already exist. But this sort if thing is much easier to do with the tools in Management Studio rather than through SQL if it's a one-off change.

Rup