I have 3 tables -
Countries CountryId | Name
States StateId | Name | CountryId
Cities CityId | Name | StateId
These 3 fields are referenced in user table (and some other tables).
Users UserId | Name | CountryId | StateId | CityId
Only country is mandatory. State and City are nullable. We will show state field only when country is updated, and then show city when state is updated. Ex:
UserID | Name | CountryId | StateId | CityId
abc | xyz | 1 | null | null
abc1 | xyz1 | 1 | 19 | null
abc2 | xyz2 | 9 | 2 | 34
Also, I have to list down Countries in a lot of places.. And also I have some tables where only Country field is referenced. for ex:
Presidents PresidentId | Country
A different approach that I thought of is -
Locations LocationId(Autoincrement int) | Country(string) | State(string) | City(string)
Users UserId | Name | LocationId
Which approach is good? Please suggest me if there is a better way of structuring the db?
Thanks in advance
The first approach is better, because in the second one you'll have multiple copies of country for each city, for example. But, for user it's enough to specify the cityId, because you can figure out the state and country from it. Also, note that the standard specifies to use nouns at singular for entity names.