Avatar of antonms
antonms asked on

Table Contraints

Hi
Is it possible to apply a constraint or equivalent to a table that prevents a record being inserted when the record to be inserted already exists but the values are swapped around?

For example, if a table had two columns: FirstName and SecondName having a record FirstName = ‘John’ and SecondName = ‘Smith’ – then when another record having FirstName =’ Smith’ and SecondName =’ John’ was about to be inserted SQL would reject it.

Good luck!
Microsoft SQL ServerMicrosoft SQL Server 2005

Avatar of undefined
Last Comment
antonms

8/22/2022 - Mon
SOLUTION
Jim Horn

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Scott Pletcher

If you want to avoid a trigger, you could also create a PERSISTED column with a unique index on it.  I can give you details on that if you'd like them.
ASKER
antonms

If possible I would prefer not to use a trigger - more info on the persisted column option would be great thanks.
ASKER CERTIFIED SOLUTION
Scott Pletcher

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
antonms

Thanks
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck