Search code examples
databasedatabase-designzipcode

Data constraints in US state/county/city/zip database?


I have a database of US zip codes and their corresponding states, cities and counties. It was supplied as a flat file and I'm trying to normalize the data and figure out exactly which entities depend on which others.

One problem I've come across is that some cities seem to exist in more than one county. I was under the impression that in the US, there is a hierarchy of State -> County -> City -> Zip.

However, this data seems to show otherwise for some cities:

Is my data set incorrect or is this actually a feature of US geography?


Solution

  • No, there isn't a clean hierarchy like that.

    You're also liable to find cities that straddle state borders (cities in two states), and ZIP codes that take in more than one city. Not long ago, there were ZIP codes that straddled state borders, too. (ZIP codes are more about the route followed to deliver mail than about geography.) There might still be some.

    As far as I know, no county is split between two states. But if there happened to be one, it wouldn't surprise me.

    Depending on your application, you might discover even weirder things. I used to have to deal with addresses in the mountains that were "in" one county geographically, but were "in" a second county for emergency services (fire, police), and "in" yet a third county for non-emergency services (water, sewer, garbage collection). It depended on where the address was in relation to mountain ridges and roads.