Add unique constraint in SQL Server 2008 GUI?

后端 未结 4 1512
借酒劲吻你
借酒劲吻你 2020-12-04 17:27

I have an existing table with data. I have just added a new column but I cannot find how to add a unique constraint on that column. Could someone please advise? Right-clicki

4条回答
  •  生来不讨喜
    2020-12-04 18:24

    Do right-click in the table designer and choose Indexes/Keys.

    enter image description here

    Indexes/Keys window will open. Click the button Add, to create the new index/key, and choose the column to be unique in the Columns property:

    enter image description here

    In the properties of the new index/key, set Type to Unique Key:

    enter image description here

    And this is the generated code for the unique constraint:

    ALTER TABLE [dbo].[Table_1] ADD  CONSTRAINT [IX_Table_1] UNIQUE NONCLUSTERED 
    (
        [myUniqueColumn] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    GO
    

提交回复
热议问题