Unique constraint across columns? Hi all,
I have a table where I need entries to be unique across two columns.
ie:
NAME UNIQUE
john true
john false
john false
I can have as many john false's as I like, but only ever one john
true.
I need to prevent two people inserting a john true at the same time.
As far as I can see, the unique contraint can only be applied to a
single column so I can't use the built in stuff.
It appears to my newbie eyes that the only way I can do this is with a
table write lock. ie:
Lock the table for writes
Do a SELECT to see if the unique entry is already in there.
Insert it if it isn't
Unlock the table.
Are there any quicker / more efficient ways? Also I'm a bit unsure of
the syntax to only insert if the select comes up empty. Can anyone
point me in the right direction?
Many thanks,
Lister |