Postal code in City / State and vice versa in the database?

I am new to SQL and relational databases, and I have what I think is a common problem.

I make a website, and when each user sends a message, he must provide the location in zip code or in City / State.

What is the best practice for this? Am I just creating a Zip Code, City and State table and querying them, or are solutions ready for this?

I am using SQL Server 2005 if that matters.

I need to be able to get the zip code based on the city / state, or I will need to spit out the city state based on the zip code.

+5
source share
11 answers

. zip- -, , , .. , - -, .

zip-, , -, . , . SQL Server, , , State, Zipcode City, . , zip- , , .

, - -, .

: SourceForge, , lat/lon .. , .

2: SourceForge, , . , /, . - , .., , , .

+9

ZipCode, CityState. , , , , , .

ZipInfo.com, , lat/long, zip type county. , , , .

+3

, , Yelp API , , , , , .

, db-center, , , .

+1

-, - . - GeoNames. - db, , , - .

+1

- , , - :

/ /, . - , . , .

, . , , , .

+1

, -API USPS , , , , , , .

, , , .

0

, . , , ?

, zip/city, , , "" . .

0

, , . , ( ). , , 6 . , , , google. . 6 , , Google, , . , , , .

ping - USPS. , / zipcode.

0

US States , , StateId StateName States, StateId auto increment.

50 ...

INSERT INTO States
        ( StateName )
        VALUES
( 'Alabama'),
( 'Alaska'),
( 'Arizona'),
( 'Arkansas'),
( 'California'),
( 'Colorado'),
( 'Connecticut'),
( 'Delaware'),
( 'District of Columbia'),
( 'Florida'),
( 'Georgia'),
( 'Hawaii'),
( 'Idaho'),
( 'Illinois'),
( 'Indiana'),
( 'Iowa'),
( 'Kansas'),
( 'Kentucky'),
( 'Louisiana'),
( 'Maine'),
( 'Maryland'),
( 'Massachusetts'),
( 'Michigan'),
( 'Minnesota'),
( 'Mississippi'),
( 'Missouri'),
( 'Montana'),
( 'Nebraska'),
( 'Nevada'),
( 'New Hampshire'),
( 'New Jersey'),
( 'New Mexico'),
( 'New York'),
( 'North Carolina'),
( 'North Dakota'),
( 'Ohio'),
( 'Oklahoma'),
( 'Oregon'),
( 'Pennsylvania'),
( 'Puerto Rico'),
( 'Rhode Island'),
( 'South Carolina'),
( 'South Dakota'),
( 'Tennessee'),
( 'Texas'),
( 'Utah'),
( 'Vermont'),
( 'Virginia'),
( 'Washington'),
( 'West Virginia'),
( 'Wisconsin'),
( 'Wyoming');
0

. (zipped, csv):

maphacks.com

-, , , , , , Dst

, ( , )

-1

.

http://www.unitedstateszipcodes.org/zip-code-database/

You can download the data for free if you use for personal / educational (from 2014-03-20).

-1
source

All Articles