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 2008 Forums
 Transact-SQL (2008)
 unique constarint

Author  Topic 

kiranmurali
Yak Posting Veteran

55 Posts

Posted - 2011-03-10 : 02:03:41
hi all,

I have a senario that

i my table there are three fields,

orgid lobid locationid

1 1 4
1 1 5

i want to bulild a unique constarint in suvh a way that locationid should not repeat same for the combination of (orgid & lobid)

pls any can help me to solve this situation

Regards,
Kiranmayee

pk_bohra
Master Smack Fu Yak Hacker

1182 Posts

Posted - 2011-03-10 : 02:47:48
You can create a unique constraint for all the 3 columns.
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-10 : 02:50:58
Use the following if table not created or If the table is created,respectively.


create table xyz(col1 int, col2 int, col3 int, CONSTRAINT uc_col1_col2_col3 UNIQUE (Col1,col2,col3))

Or

Alter table xyz add CONSTRAINT uc_col1_col2_col3 UNIQUE (Col1,col2,col3)

Cheers
MIK
Go to Top of Page
   

- Advertisement -