Question

Where can I find a list of the US States in a form for importing into my database?

SQL would be ideal, otherwise CSV or some other flat file format is fine.

Edit: Complete with the two letter state codes

Was it helpful?

Solution

I needed this a few weeks ago and put it on my blog as SQL and Tab Delimited. The data was sourced from wikipedia in early January so should be up to date.

US States: http://www.john.geek.nz/index.php/2009/01/sql-tips-list-of-us-states/

I use the Worlds Simplest Code Generator if I need to add columns or remove some of the fields - http://secretgeek.net/wscg.asp

I've also done Countries of the world and International Dialling Codes too.
Countries: http://www.john.geek.nz/index.php/2009/01/sql-tips-list-of-countries/
IDC's: http://www.john.geek.nz/index.php/2009/01/sql-tips-list-of-international-dialling-codes-idcs/

Edit: New: Towns and cities of New Zealand

OTHER TIPS

Depending on why you need the states, it is worth keeping in mind that there are more than 50 valid state codes. For someone deployed outside the USA, it is annoying to come across websites that do not allow address entry with perfectly valid state codes like AE and AP. A better resource would be USPS.

Cut/Paste these into notepad and then import..should be easy enough - there are only 50 after all:

 Alabama
 Alaska
 Arizona
 Arkansas
 California
 Colorado
 Connecticut
 Delaware
 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
 Rhode Island
 South Carolina
 South Dakota
 Tennessee
 Texas
 Utah
 Vermont
 Virginia
 Washington
 West Virginia
 Wisconsin
 Wyoming

Out of interest: As there are only 50 and they rarely change, couldn't you not just manually create such a list from a source and put it on a public webspace?

In response to @cspoe7's astute observation, here is a query with all valid states and their abbreviations according to USPS. I have them sorted here by category (official US states, District of Columbia, US territories, military "states") and then alphabetically.

INSERT INTO State (Name, Abbreviation)
VALUES
('Alabama','AL'), -- States
('Alaska','AK'),
('Arizona','AZ'),
('Arkansas','AR'),
('California','CA'),
('Colorado','CO'),
('Connecticut','CT'),
('Delaware','DE'),
('Florida','FL'),
('Georgia','GA'),
('Hawaii','HI'),
('Idaho','ID'),
('Illinois','IL'),
('Indiana','IN'),
('Iowa','IA'),
('Kansas','KS'),
('Kentucky','KY'),
('Louisiana','LA'),
('Maine','ME'),
('Maryland','MD'),
('Massachusetts','MA'),
('Michigan','MI'),
('Minnesota','MN'),
('Mississippi','MS'),
('Missouri','MO'),
('Montana','MT'),
('Nebraska','NE'),
('Nevada','NV'),
('New Hampshire','NH'),
('New Jersey','NJ'),
('New Mexico','NM'),
('New York','NY'),
('North Carolina','NC'),
('North Dakota','ND'),
('Ohio','OH'),
('Oklahoma','OK'),
('Oregon','OR'),
('Pennsylvania','PA'),
('Rhode Island','RI'),
('South Carolina','SC'),
('South Dakota','SD'),
('Tennessee','TN'),
('Texas','TX'),
('Utah','UT'),
('Vermont','VT'),
('Virginia','VA'),
('Washington','WA'),
('West Virginia','WV'),
('Wisconsin','WI'),
('Wyoming','WY'),
('District of Columbia','DC'),
('American Samoa','AS'), -- Territories
('Federated States of Micronesia','FM'),
('Marshall Islands','MH'),
('Northern Mariana Islands','MP'),
('Palau','PW'),
('Puerto Rico','PR'),
('Virgin Islands','VI'),
('Armed Forces Africa','AE'), -- Armed Forces
('Armed Forces Americas','AA'),
('Armed Forces Canada','AE'),
('Armed Forces Europe','AE'),
('Armed Forces Middle East','AE'),
('Armed Forces Pacific','AP')

If you need to memorize them, let Wakko help you :)

You can download a lot of lists on http://www.freebase.com/ .

http://www.geonames.org/export/

The GeoNames geographical database is available for download free of charge under a creative commons attribution license. It contains over eight million geographical names and consists of 6.5 million unique features whereof 2.2 million populated places and 1.8 million alternate names. All features are categorized into one out of nine feature classes and further subcategorized into one out of 645 feature codes. (more statistics ...). The data is accessible free of charge through a number of webservices and a daily database export.

You could use google sets to make a list of all states as well as lists of more or less anything.

If you need only 52 states SQL server script you can use the following query: solved

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');

I'm just gonna put this list of the United States bash/linux format here so I can save someone some time:

alabama|alaska|arizona|arkansas|california|colorado|connecticut|delaware|florida|georgia|hawaii|idaho|illinois|indiana|iowa|kansas|kentucky|louisiana|maine|maryland|massachusetts|michigan|minnesota|mississippi|missouri|montana|nebraska|nevada|newhampshire|newjersey|newmexico|newyork|northcarolina|northdakota|ohio|oklahoma|oregon|pennsylvania|rhodeisland|southcarolina|southdakota|tennessee|texas|utah|vermont|virginia|washington|westvirginia|wisconsin|wyoming
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top