Link to home
Start Free TrialLog in
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!
SOLUTION
Avatar of Jim Horn
Jim Horn
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of antonms
antonms

ASKER

If possible I would prefer not to use a trigger - more info on the persisted column option would be great thanks.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of antonms

ASKER

Thanks