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)
 Prevent duplicate records on multiple line

Author  Topic 

ConfusedAgain
Yak Posting Veteran

82 Posts

Posted - 2012-09-07 : 06:38:40
I am trying to stop the user entering duplicate records against mulitple columns where these columns are not primary keys.

eg: If the user enters Tom in fname and Thumb in lname

I want to prevent them entering that name again in those columns.

Abu-Dina
Posting Yak Master

206 Posts

Posted - 2012-09-07 : 06:50:49
So it's a unique constraint on two columns.

Something like this:

ALTER TABLE SomeTable ADD CONSTRAINT uc_SomeConstraint UNIQUE(fname, lname)


I believe this also creates a unique index. So if that's not what you want then you'll have to try another method like using a trigger.
Go to Top of Page

ConfusedAgain
Yak Posting Veteran

82 Posts

Posted - 2012-09-07 : 09:45:32
Works very niceley.

Thanks you
Go to Top of Page
   

- Advertisement -