views:

55

answers:

3

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

A: 

Primary key constraint?

CREATE TABLE [dbo].[Table1](
    [Id1] [int] NOT NULL,
    [Id2] [int] NOT NULL,
    [AnotherColumn] [varchar](256) NOT NULL,
 CONSTRAINT [PK_Id1_Id2] PRIMARY KEY CLUSTERED 
(
    [Id1] ASC,
    [Id2] ASC
)
joerage
+2  A: 

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)
Mark Byers
Perfect. Thank you.
Byron Whitlock
A: 

Are you talking about check constraints?

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