Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add unique constraint in SQL Server 2008 GUI?

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-clicking and selecting "check constraints" wasn't helpful.

like image 923
mezamorphic Avatar asked Nov 30 '12 10:11

mezamorphic


People also ask

How do I add a unique constraint to an existing column in SQL Server?

Set column as unique in SQL Server from the GUI:Open SQL Server Management Studio. Right click your Table, click "Design". Right click the column you want to edit, a popup menu appears, click Indexes/Keys. Click the "Add" Button.

How do I add a unique key constraint to an existing table in SQL?

The syntax for creating a unique constraint using an ALTER TABLE statement in SQL Server is: ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column1, column2, ... column_n); table_name.

How do you give a unique constraint?

The syntax for creating a unique constraint using an ALTER TABLE statement in MySQL is: ALTER TABLE table_name ADD CONSTRAINT constraint_name UNIQUE (column1, column2, ... column_n); table_name.

How do I create a unique key on multiple columns in SQL Server?

To define a UNIQUE constraint, you use the UNIQUE keyword followed by one or more columns. You can define a UNIQUE constraint at the column or the table level. Only at the table level, you can define a UNIQUE constraint across multiple columns.


1 Answers

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

enter image description here

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:

enter image description here

like image 147
marc_s Avatar answered Sep 25 '22 02:09

marc_s