MySQL Database Design for City/State

citydatabaseMySQLstatezipcode

I am building a site where there will be a bunch of companies and their business listing, so they will have their Address, City, State, Zip Code, etc.

I found this website here:
http://jesseprice.com/mysql-city-state-zip-latitude-longitude-database/ which has a database of all city, state, zip, county, lat, long.

I imported the database above, so my question is how would I connect this to my companies table? And when a company signs up, I guess I could make a drop down for the state, and then it will drop down to the cities found in that state pulling from the database so they choose from the those, and then the zip code. Would that work? So they wouldn't have to enter it in themselves?

I'm just a little confused on how to do this properly and all make it work together.

Thank you.

Best Answer

Option 1:

Add ALL fields to your address table, referencing the selected table on additions, placing city, state, zip, county, lat and long into your table.

Advantages:

  • You can provide international support without making updates to the downloaded table.
  • You can update the downloaded table without loss of data (unlikely)
  • All data is available in one single-table query.
  • lat/lon searches should be faster.
  • Allows for flexibility in addresses that may not be available in the downloaded table.

Option 2:

Add a zip field only, and for all lookups, pull the data from the downloaded table.

Advantages:

  • Normalized - all records are in one table. Less drive space.

I would actually recommend adding the fields into your managed table, and keep the downloaded table as a read-only, replaceable reference table.