Quantcast
Channel: Active questions tagged surrogate-key - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 31

Composite primary key plus a separate (surrogate) id column for foreign key references

$
0
0

I am trying to build a database about locations like so:

  • Country → Region → Town

Countries will be populated with a list of pre-defined worldwide countries, regions & towns are input by users.

Region may not apply to every location and so a blank string will be allowed (hence the many to many link table).

This is the best design I have come up with:

ER Diagram

The town_id column is set to AUTO_INCREMENT & UNIQUE. It is then used as a foreign key reference in other tables.

The town column on its own is not UNIQUE as you may have the same town name in multiple places.

Is the towns table correct?

The reason I ask is because it just seems odd to me to have the town_id as the reference, however this cannot be included or used as the primary key (because if it did, it would cause duplicates)?

I would welcome feedback if this approach is correct.


Viewing all articles
Browse latest Browse all 31

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>