Home All Groups Group Topic Archive Search About

Add composite primary key

Author
21 Oct 2005 2:52 PM
Rick Charnes
I'm a bit unclear on the syntax to add a composite (multiple columns)
primary key to a table.  The columns already exist.  Thanks.

Author
21 Oct 2005 2:56 PM
Anith Sen
Do:

ALTER TABLE tbl ADD CONSTRAINT pk PRIMARY KEY ( col1, col2 )

--
Anith
Author
21 Oct 2005 3:00 PM
Stu
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
Author
21 Oct 2005 3:02 PM
Mark White
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

Show quote
"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.

AddThis Social Bookmark Button