I have two tables.
- A: id, email, … (email can have duplicates)
- B: id, email, … (email is unique)
I want to only allow new entries in B where the email already exists in A.
Is there some way to do this via FKs or would I need some kind of trigger?
I have two tables.
I want to only allow new entries in B where the email already exists in A.
Is there some way to do this via FKs or would I need some kind of trigger?
2
Answers
You can add foreign key constraint on the Table B on this Email column, so that it will maintain the integrity.
The unique emails should be stored in a separate table
X
:or, better:
Then, both tables
A
andB
should have a columnemail
oremail_id
referencing either theemail
or theid
of the tableX
:or: