Say we have the following 3 tables:
tUsers (ID, name, countryID, regionID)
------
1 | Joe | 1 | 1
2 | Sue | NULL | 2
3 | Bob | 2 | NULL
4 | Amy | NULL | NULL
tCountries (ID, name, regionID)
------
1 | USA | 1
2 | China | 3
tRegions (ID, name)
------
1 | North America
2 | Central America
3 | East Asia
4 | Europe
Is there a way from the DB to prevent a user from having mismatched Country/Region while still allowing one or both to be NULL? For example, the query UPDATE tUsers SET regionID=4 WHERE ID = 3
would fail since Bob's country is China which is not in region Europe.
tCountry
for every entry intRegion
but that seems excessive.