Add unique constraint in SQL Server 2008 GUI?

这一生的挚爱 提交于 2019-11-27 18:06:26

You need to right-click in the table designer and pick Indexes/Keys:

Then a dialog pops up and you can add a new index to the list of indices (on the left hand side) and define it to be a unique index:

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

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:

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

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

Try right clicking and choosing Indexes/Keys, adding a new index and setting Is Unique to Yes.

dinesh.k

You just Right Click from which column you need to add unique key from your table and you can select the Indexes/Keys. Then you can add or delete the column which you want to set unique key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!