Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
jmontgomery
Starting Member
3 Posts |
Posted - 2008-06-06 : 22:45:01
|
I like to use the management console to design tables, but havebeen unable to figure out how to add a unique column constraint.I have a primary key defined in col1 and want to make col2, char(10),unique, but keep col1 as the primary key.I have tried the Check constraint menu path, but do not know howto write the expression.If I go along the Indexes/Key path, I am forced to change the primarykey which I do not want to do.Can anyone help?TIA, Joe |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-06-06 : 23:24:13
|
Expend table in ssms, right click on constraints and choose new constraint. |
 |
|
jmontgomery
Starting Member
3 Posts |
Posted - 2008-06-06 : 23:32:47
|
Thx for the reply, but I need more help. I do not know how towrite the required espression to make col2 unique. |
 |
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-06-07 : 00:19:46
|
If you get check constraint there, delete it and close the page. Right click in table design and choose indexes/keys, choose column then pick unique key in type field. Save the table once done. |
 |
|
jmontgomery
Starting Member
3 Posts |
Posted - 2008-06-07 : 10:14:15
|
Thx, I do now understand how to create the constraint which reallyis an index via ssmc. I also was puzzled for a moment when I did notsee the new constraint listed under the table-constraint node, butthen looked under the index node & see it; IX_T3.Thx again for your help --- Joe |
 |
|
Peace2007
Posting Yak Master
239 Posts |
Posted - 2008-06-23 : 05:06:33
|
Unique constraint is actually an index in SQL2005 so it's intelligent enough to transfer it to the indexes. for creating unique constraint you can also use the following query: Alter table [tablename] add constraint [constraint name] Unique NonClustered (field name) |
 |
|
|
|
|
|
|