The problem seems simple, but I can’t seem to find a way to implement it in MS Access. I have a set of countries, and a set of regions inside those countries. For the purpose of modelling gas exchanges between countries or regions, I’m defining “balancing zones”. This balancing zone can either be a whole country, or a region, like the northern part of France.
Until now I had three tables : country->region->balancing zone. In this model, some regions are “real” regions, i.e. real country sub-sets, some are identical to the countries. I used a single character tag to identify the regions in combination with the country code, and the special character “x” to express the fact that this particular region is identical to the country. However with this approach, I cannot express the fact that “x” is special, and that when used, it designates the whole country.
It would seem natural to me to use NULL instead. However, in this case I cannot have an index on (country, tag) that will be unique, as Access will allow multiple (country, NULL) records.
Has anyone got an idea on this ?
It seems you need something like this:
In the BALANCING_ZONE table, both COUNTRY_ID and REGION_ID are NULL-able, but the CHECK enforces that exactly one of them is non-NULL at any given time.
So, to connect the balancing region to a country, simply set the BALANCING_ZONE.COUNTRY_ID, and leave the BALANCING_ZONE.REGION_ID NULL. To connect it to a region, do the reverse.
Unfortunately, Access only supports MATCH FULL behavior of partial foreign keys. If it supported MATCH SIMPLE (as most DBMSes), you could also do something like this:
In the BALANCING_ZONE table, COUNTRY_ID is not NULL-able and REGION_NO is NULL-able.
To connect the balancing zone to a country, simply set BALANCING_ZONE.COUNTRY_ID and leave BALANCING_ZONE.REGION_NO as NULL. To connect to a region, set both.