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.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 Unique column constraint

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 have
been 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 how
to write the expression.

If I go along the Indexes/Key path, I am forced to change the primary
key 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.
Go to Top of Page

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 to
write the required espression to make col2 unique.
Go to Top of Page

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.
Go to Top of Page

jmontgomery
Starting Member

3 Posts

Posted - 2008-06-07 : 10:14:15
Thx, I do now understand how to create the constraint which really
is an index via ssmc. I also was puzzled for a moment when I did not
see the new constraint listed under the table-constraint node, but
then looked under the index node & see it; IX_T3.

Thx again for your help --- Joe

Go to Top of Page

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)
Go to Top of Page
   

- Advertisement -