To a point, if you want "can be in A or B, but not both"
This is the "super key/sub type" pattern
Create a new table AB that has a 2 columns
- SomeUniqueValue, PK
- WhichChild char(1), limited to 'a' or 'b'
There is also a unique constraint on both columns
Then
- Add a WhichChild column to tables A and B. In A, it is always 'a'. In B, always 'b'
- Add foreign keys from A to AB and B to AB on both columns
Now, SomeUniqueValue can be in only A or B.
Note: in proper RDBMS you'd use check constraints or computed columns to restrict WhichChild to 'a' or 'b' as needed. But MySQL is limited so you need to use triggers in MySQL. However, this is simpler then testing table B for each insert in A etc