Creating composite primary key in SQL Server

后端 未结 4 2046
天涯浪人
天涯浪人 2020-12-09 09:45

How to add composite primary keys in SQL Server 2008?

I have a table as follows.

testRequest (wardNo nchar(5)
            , BHTNo nchar(5)
                   


        
4条回答
  •  一个人的身影
    2020-12-09 10:10

    If you use management studio, simply select the wardNo, BHTNo, testID columns and click on the key mark in the toolbar.

    enter image description here

    Command for this is,

    ALTER TABLE dbo.testRequest
    ADD CONSTRAINT PK_TestRequest 
    PRIMARY KEY (wardNo, BHTNo, TestID)
    

提交回复
热议问题