Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Alter Constrain

Author  Topic 

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2011-11-15 : 08:25:12
i have one table "emp"
in table "emp_id" is a primary key
ALTER TABLE dbo.Emp ADD CONSTRAINT
PK_Emp PRIMARY KEY CLUSTERED
(
Emp_id
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

now i want to add one more column in primary key
how to add one more column in primary key with sintex

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-11-15 : 08:30:32
Drop PK_Emp constraint first, and then recreate and include both required columns.

ALTER TABLE dbo.Emp
DROP CONSTRAINT PK_Emp

ALTER TABLE dbo.Emp ADD CONSTRAINT
PK_Emp PRIMARY KEY CLUSTERED
(
Emp_id,
First_name
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]

--------------------------
http://connectsql.blogspot.com/
Go to Top of Page

chiragvm
Yak Posting Veteran

65 Posts

Posted - 2011-11-15 : 08:38:23
hello lionofdezert
thanks for replay
but is it mandatory to first delete current primary key constrain?
bcoz i have already have fk for this table to other table
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2011-11-15 : 09:34:13
Yes you have to recreate it as there is no ALTER TABLE ALTER CONSTRAINT available :P

--------------------------
http://connectsql.com/
Go to Top of Page
   

- Advertisement -