How do I make a composite key with SQL Server Management Studio?

Viewed 193881

How do I make a composite key with SQL Server Management Studio?

I want two INT columns to form the identity (unique) for a table

8 Answers

Adding to @Roatin Marth's answer to make the Key clustered:

-- Sample Table
create table myTable 
(
    Column1 int not null,
    Column2 int not null
)
GO

-- Add Constraint
ALTER TABLE myTable
    ADD CONSTRAINT pk_myConstraint PRIMARY KEY CLUSTERED (Column1,Column2)
GO
Related