Reputation: 26771
How would one structure a database where you have City
, State
, and Country
, and Cities sometimes have states and sometimes don't? Would you simply put State_ID
(default NULL
) and Country_ID
in City
or is there a better way to approach it?
Upvotes: 1
Views: 97
Reputation: 26771
Going to accept the answer offered. But just want to note that one other approach not mentioned here would be a City_States
many to many table. This would be an especially useful approach for some cities which are in two states.
Upvotes: 0
Reputation: 1642
If your DBA's a stickler for really tight normalization, an alternative would be to have special "No State" records in the State
table. You would need one of these for each Country
(at least, each one that has "stateless" cities).
Upvotes: 0
Reputation: 4476
Your approach seems spot on. If there is no enforceable hierarchy, then you're not left with much choice.
When the real world doesn't conform to our schema, then we've got no choice than to make our schema conform to the real world.
Upvotes: 3