开发者

creating a table with a primary key and an unique key [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ag开发者_StackOverflowo.

Improve this question

i 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)
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜