Byron Whitlock
Byron Whitlock

Reputation: 53921

How do I create a multi-column constraint in SQL Server?

I know this is very simple, but how do I do this in plain SQL?

Upvotes: 0

Views: 434

Answers (2)

UserControl
UserControl

Reputation: 15179

Are you talking about check constraints?

alter table MyTable add constraint CC_Dates check (FromDate < ToDate)

Upvotes: 0

Mark Byers
Mark Byers

Reputation: 839224

For a unique constraint during table creation:

CREATE TABLE T1 (
    Col1 int NOT NULL,
    Col2 int NOT NULL,
    UNIQUE (Col1, Col2)
)

After table creation:

ALTER TABLE T1 ADD UNIQUE (Col1, Col2)

Upvotes: 3

Related Questions