How to set unique key in SQL Server 2005 .?
How to set unique key constraint in SQL Server 2005? Not through script or query.
In management studio table designer right click the table and choose "Indexes/Keys" from the popup menu.
Select the column(s) that comprise the key and choose "Unique Key" for the "Type" option.
To add a unique key without scripting, follow these steps:
- Right click the table in question and select Design
- Right click the header of the table design and select Indexes/Keys
- In the window that appears, click Add
- In the properties window that appears, click the ellipsis (...) button next to the column names and select the columns that make up the unique key
- Change the type to Unique Key
Once you've done this, click close and save your table.
If you'd rather have a primary key, such as an auto incrementing integer
- Start a new table, or open the existing table in the table designer
- Add a column named what you want with the Data Type int
- Right click the column's row header and click "Set Primary Key"
- In the column properties window, expand the identity specification property
- Change (Is Identity) to Yes.
If you literally just want to set an existing column as a primary key:
- Open the table in Table Design (right-click > Design)
- Right click the column header and choose set key, or use the key button in the toolbar