Pages

Google Analytics Alternative

Search This Blog

Monday, December 6, 2010

SQL - ISO Country Names and Codes

SQL - ISO Country Names and Codes
This document provides the necessary SQL statements for ISO 3166 country names and two and three letter codes. This page and the data are in UTF-8 encoding.

Create Country Table



Table is called base_country as it follows Edoceo naming conventions, change as necessary. This is for a PostgreSQL database, CREATE TABLE statements may need to be altered for your RDBMS.

create table base_country (
id integer primary key,
iso2 char(2),
iso3 char(3),
name_en varchar(64),
name_fr varchar(64),
name_de varchar(64)
);




Create indexes as necessary, which may not be as this table is so small.

Insert the Country Data



This SQL should work on any SQL-99 compliant RDBMS.





INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (1, 'AF', 'AFG', 'Afghanistan', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (2, 'AX', 'ALA', 'Åland Islands', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (4, 'DZ', 'DZA', 'Algeria (El Djazaïr)', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (3, 'AL', 'ALB', 'Albania', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (5, 'AS', 'ASM', 'American Samoa', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (6, 'AD', 'AND', 'Andorra', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (7, 'AO', 'AGO', 'Angola', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (8, 'AI', 'AIA', 'Anguilla', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (9, 'AQ', 'ATA', 'Antarctica', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (10, 'AG', 'ATG', 'Antigua and Barbuda', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (11, 'AR', 'ARG', 'Argentina', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (12, 'AM', 'ARM', 'Armenia', NULL);
INSERT INTO base_country (id, iso2, iso3, name_en, name_fr) VALUES (13, 'AW', 'ABW', 'Aruba', NULL);