Printed from http://kimbriggs.com

Create State Table MySQL Script: Values for US States and Abbreviations

Summary: If you have a database and you don't need a full US state and zip database, it might be helpful to have a look-up table of state names and abbreviations. I searched for a little while and didn't find anything simple right away, so here is a little SQL script to make a state look-up table. It can handle over 65,000 records and state / province names up to 32 characters, so you can expand your horizons if needed.

#
# 2007-05 http://kimbriggs.com/
# Creates a table of state IDs, names, and abbreviations. Over 65,000 records allowed.
# Additional insert statement fills table for US states and DC.
#


drop table if exists state;


create table state
(
state_id   smallint    not null unsigned auto_increment comment 'PK: Unique state ID',
state      varchar(32) not null comment 'State name with first letter capital',
state_abbr varchar(8)  comment 'Optional state abbreviation (US is 2 capital letters)',

primary key (state_id)
);


insert into state
values
(NULL, 'Alabama', 'AL'),
(NULL, 'Alaska', 'AK'),
(NULL, 'Arizona', 'AZ'),
(NULL, 'Arkansas', 'AR'),
(NULL, 'California', 'CA'),
(NULL, 'Colorado', 'CO'),
(NULL, 'Connecticut', 'CT'),
(NULL, 'Delaware', 'DE'),
(NULL, 'District of Columbia', 'DC'),
(NULL, 'Florida', 'FL'),
(NULL, 'Georgia', 'GA'),
(NULL, 'Hawaii', 'HI'),
(NULL, 'Idaho', 'ID'),
(NULL, 'Illinois', 'IL'),
(NULL, 'Indiana', 'IN'),
(NULL, 'Iowa', 'IA'),
(NULL, 'Kansas', 'KS'),
(NULL, 'Kentucky', 'KY'),
(NULL, 'Louisiana', 'LA'),
(NULL, 'Maine', 'ME'),
(NULL, 'Maryland', 'MD'),
(NULL, 'Massachusetts', 'MA'),
(NULL, 'Michigan', 'MI'),
(NULL, 'Minnesota', 'MN'),
(NULL, 'Mississippi', 'MS'),
(NULL, 'Missouri', 'MO'),
(NULL, 'Montana', 'MT'),
(NULL, 'Nebraska', 'NE'),
(NULL, 'Nevada', 'NV'),
(NULL, 'New Hampshire', 'NH'),
(NULL, 'New Jersey', 'NJ'),
(NULL, 'New Mexico', 'NM'),
(NULL, 'New York', 'NY'),
(NULL, 'North Carolina', 'NC'),
(NULL, 'North Dakota', 'ND'),
(NULL, 'Ohio', 'OH'),
(NULL, 'Oklahoma', 'OK'),
(NULL, 'Oregon', 'OR'),
(NULL, 'Pennsylvania', 'PA'),
(NULL, 'Rhode Island', 'RI'),
(NULL, 'South Carolina', 'SC'),
(NULL, 'South Dakota', 'SD'),
(NULL, 'Tennessee', 'TN'),
(NULL, 'Texas', 'TX'),
(NULL, 'Utah', 'UT'),
(NULL, 'Vermont', 'VT'),
(NULL, 'Virginia', 'VA'),
(NULL, 'Washington', 'WA'),
(NULL, 'West Virginia', 'WV'),
(NULL, 'Wisconsin', 'WI'),
(NULL, 'Wyoming', 'WY')
;

Here is just the MySQL create state table script in plain text.

If you are working on the states, you probably already have a MySQL create contact table script.

HTH,
Kim

 
CC License Ubuntu Bluefish Editor Graphics by GIMP Eliminate DRM Get Firefox php.net Play Ogg Valid XHTML 1.0 why the icons?