How can I create a SQL unique constraint based on 2 columns?

前端 未结 5 1417
心在旅途
心在旅途 2020-12-08 01:45

I have a Table like this one:

|UserId   |  ContactID |  ContactName 
---------------------------------------
| 12456   |  Ax759     |  Joe Smith
| 12456   |          


        
5条回答
  •  [愿得一人]
    2020-12-08 02:33

    You can add unique constraint tou your fields:

    ALTER TABLE YourTable
    ADD CONSTRAINT UQ_UserId_ContactID UNIQUE(UserId, ContactID)
    

提交回复
热议问题