creating a table with a primary key and an unique key [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ag开发者_StackOverflowo.
Improve this questioni am using sql server 2000 i want to create a table having id as primary key and one more column having unique key constraint.
This should do that.
CREATE TABLE [dbo].[TestTable]
(
[id] [int] NOT NULL,
[otherValue] [int] NOT NULL,
CONSTRAINT [IX_OtherValye] UNIQUE NONCLUSTERED
(
[otherValue] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [MyTable]
(
ID INT NOT NULL,
SomeUniqueColumn varchar(20) NOT NULL,
CONSTRAINT PK_MyTable PRIMARY KEY(ID),
CONSTRAINT U_MyTable UNIQUE(SomeUniqueColumn)
)
精彩评论