Friday, February 24, 2012

Add composite primary key

I'm a bit unclear on the syntax to add a composite (multiple columns)
primary key to a table. The columns already exist. Thanks.ALTER TABLE dbo.TableName ADD CONSTRAINT
PK_ConstraintName PRIMARY KEY NONCLUSTERED
(
Col1,
Col2
) ON [PRIMARY]
When in doubt, you can always perform the action in Enterprise Manager
and then look at the change script to help clear up basic syntax
things.
HTH,
Stu|||Do:
ALTER TABLE tbl ADD CONSTRAINT pk PRIMARY KEY ( col1, col2 )
Anith|||Roughly this at table creation:
CONSTRAINT PK_NameIt PRIMARY KEY CLUSTERED (Column1, Column2, Column3)
Obviously if you need a NONCLUSTERED PK, use that syntax instead.
Mark
"Rick Charnes" <rickxyz--nospam.zyxcharnes@.thehartford.com> wrote in message
news:MPG.1dc2cab9b0d541d8989902@.msnews.microsoft.com...
> I'm a bit unclear on the syntax to add a composite (multiple columns)
> primary key to a table. The columns already exist. Thanks.

No comments:

Post a Comment