I have two tables A
and B
each with unique constraints for appid
and name
columns to ensure name
is unique for each appid
.
However, now I also need to ensure that name
value is unique across the both tables.
I can write UNION
query to check this also but is there something like
select count(1) from ['A', 'B'] where appid='123' AND name='item list check'
2
Answers
This will only retrieve records that are present in both tables :
To avoid race conditions, you will have to lock the rows. You could write an
AFTER INSERT
trigger like this:The trigger itself would be: