October 8, 2015 at 9:49 am
Table: tmpHCDAXP
Primary Key: PK_tmoHCDAXP,clustered, unique, primary key located on PRIMARY,
Constraint Keys: DXFORM, DXFTYP, DXPCOD, DXPSDT, DXSSDT
How do I remove the primary key and then add a different one ( where I will use the came columns but will add one more by the name IDX )
I need to be able to do this via SQL code
BTW- That table is empty so will not affect any data
October 8, 2015 at 10:19 am
you will nedd to drop the current constraint, then add the new one. https://msdn.microsoft.com/en-CA/library/ms190273.aspx
ALTER TABLE tmpHCDAXP
DROP CONSTRAINT PK_tmoHCDAXP;
ALTER TABLE tmpHCDAXP
ADD CONSTRAINT PK_tmoHCDAXP primary key clustered (DXFORM, DXFTYP, DXPCOD, DXPSDT, DXSSDT);
October 8, 2015 at 10:26 am
you'll need to drop the constraint and recreate it, if you don't specify any different the clustered index will be create on the PK columns.
Drop the constraint using
ALTER TABLE [schema].
DROP CONSTRAINT [PK_name]
Create the constraint using
ALTER TABLE [schema].
ADD CONSTRAINT [PK_name] PRIMARY KEY
(
[column_name] ASC,
[column_name2] ASC,
etc
)
-----------------------------------------------------------------------------------------------------------
"Ya can't make an omelette without breaking just a few eggs" 😉
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply