edoceo

SQL - US States and Territories

Create a table like this, add more columns if needed.

create table state (
  id serial primary key,
  code char(2) not null,
  name varchar(64) not null
);

Now insert these records

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

Loading Comments from Disqus...