Skip to main content

Database Architecture

The Countries States Cities database follows a hierarchical structure with clear relationships between geographical entities. The schema is designed to be normalized, efficient, and consistent across all supported database formats.

Core Tables

1. Regions Table

The top-level geographical divisions based on UN regional classifications.
integer
required
Unique identifier for the region (Primary Key)
varchar(100)
required
Official name of the region (e.g., “Europe”, “Asia”, “Africa”)
varchar(255)
Wikidata identifier for additional reference data
timestamp
Record creation timestamp
timestamp
Last modification timestamp
Sample Data:

2. Subregions Table

Subdivisions of regions providing more granular geographical classification.
integer
required
Unique identifier for the subregion (Primary Key)
varchar(100)
required
Official name of the subregion (e.g., “Western Europe”, “Southern Asia”)
integer
required
Foreign key reference to the parent region
varchar(255)
Wikidata identifier for additional reference data
timestamp
Record creation timestamp
timestamp
Last modification timestamp
Sample Data:

3. Countries Table

Complete country information with ISO codes, economic data, and geographical coordinates.
integer
required
Unique identifier for the country (Primary Key)
varchar(100)
required
Official English name of the country
char(3)
required
ISO 3166-1 alpha-3 code (e.g., “USA”, “IND”, “GBR”)
char(2)
required
ISO 3166-1 alpha-2 code (e.g., “US”, “IN”, “GB”)
char(3)
ISO 3166-1 numeric code
varchar(255)
International dialing code (e.g., “+1”, “+91”, “+44”)
varchar(255)
Name of the country’s capital city
char(3)
ISO 4217 currency code (e.g., “USD”, “EUR”, “INR”)
varchar(100)
Full name of the currency
varchar(10)
Currency symbol (e.g., ”$”, ”€”, ”₹”)
varchar(10)
Top-level domain (e.g., “.us”, “.in”, “.uk”)
varchar(255)
Native name of the country in local language/script
varchar(100)
Region name (denormalized for quick access)
varchar(100)
Subregion name (denormalized for quick access)
integer
Foreign key reference to the regions table
integer
Foreign key reference to the subregions table
varchar(100)
Demonym for country citizens (e.g., “American”, “Indian”, “British”)
decimal(10,8)
Geographical latitude coordinate of country center
decimal(11,8)
Geographical longitude coordinate of country center
varchar(10)
Unicode emoji flag representation
varchar(20)
Unicode code points for the flag emoji
integer
Country population (may be null for territories with no dedicated census)
decimal
Gross domestic product in USD billions (approximate)
decimal
Total area in square kilometres
varchar(255)
Human-readable postal code format pattern (e.g., ##### for US zip codes)
varchar(255)
Regular expression for validating postal codes for this country
json
JSON array of timezone objects for the country. Each object contains zoneName, gmtOffset, gmtOffsetName, abbreviation, and tzName.
json
JSON object of country name translations keyed by locale code (e.g., "fr": "États-Unis", "de": "Vereinigte Staaten"). 19 languages supported.
varchar(255)
Wikidata identifier for cross-referencing additional metadata
Sample Data:

4. States Table

Administrative divisions within countries (states, provinces, regions, etc.).
integer
required
Unique identifier for the state (Primary Key)
varchar(255)
required
Official name of the state/province/region
integer
required
Foreign key reference to the parent country
char(2)
required
ISO 2-letter country code for quick reference
varchar(100)
Country name (denormalized for performance)
varchar(10)
Official state/province code when available
varchar(191)
Type of administrative division (state, province, region, municipality, etc.)
varchar(10)
FIPS (Federal Information Processing Standards) code, primarily used for US states
varchar(10)
ISO 3166-2 subdivision code (e.g., US-CA, IN-MH, GB-ENG)
integer
Hierarchy level within the country. 1 = top-level region/state, 2 = department/province. Used in countries with multi-tier administration (France, Italy). Null for countries with a flat structure.
integer
Foreign key to the parent state row for level-2 subdivisions (e.g., a French department points to its region). Null for level-1 states.
varchar(255)
State name in the local/native language and script
varchar(255)
Primary IANA timezone identifier for the state (e.g., America/Los_Angeles)
json
JSON object of state name translations keyed by locale code
integer
State population estimate
varchar(255)
Wikidata identifier for cross-referencing additional metadata
decimal(10,8)
Geographical latitude coordinate of state center
decimal(11,8)
Geographical longitude coordinate of state center
Sample Data:

5. Cities Table

Cities, towns, and other populated places within states/countries.
integer
required
Unique identifier for the city (Primary Key)
varchar(255)
required
Official name of the city/town
integer
required
Foreign key reference to the parent state
varchar(10)
State code for quick reference
varchar(255)
State name (denormalized for performance)
integer
required
Foreign key reference to the country
char(2)
required
ISO 2-letter country code for quick reference
varchar(100)
Country name (denormalized for performance)
varchar(191)
Place classification inherited from GeoNames (e.g., city, town, adm2, county). See the city types reference for all 35 values and filtering guidance.
integer
Administrative hierarchy level within the state, mirroring the state-level structure where applicable
integer
Foreign key to the parent city row for nested subdivisions (e.g., a district within a city)
varchar(255)
City name in the local/native language and script
integer
City population estimate
varchar(255)
IANA timezone identifier for the city (e.g., America/Los_Angeles)
json
JSON object of city name translations keyed by locale code
decimal(10,8)
required
Geographical latitude coordinate
decimal(11,8)
required
Geographical longitude coordinate
varchar(255)
Wikidata identifier for additional reference data
Sample Data:

6. Postcodes Table

844,248 postal codes across 125 countries with type classification and source tracking.
integer
required
Unique identifier for the postcode record (Primary Key)
varchar(20)
required
The postal / ZIP code string (e.g., 90210, SW1A 1AA, 110001)
char(2)
required
ISO 3166-1 alpha-2 country code linking to the countries table
enum
Granularity of the postcode. One of:
  • full — complete postcode identifying a specific delivery point or small area
  • outward — first part of a UK-style postcode identifying the postal district
  • sector — intermediate granularity within a district
  • district — broadest level, covering an entire postal district
varchar(255)
Data source attribution for the postcode record
varchar(255)
Name of the locality or area associated with this postcode
varchar(255)
Wikidata identifier for cross-referencing
Sample Data:
The postcodes table is available in the self-hosted database exports. See the postcodes reference for coverage details and query examples.

Indexes and Performance

Primary Indexes

All tables include clustered primary key indexes on the id field for optimal performance.

Foreign Key Indexes

Search Indexes

For full-text search capabilities, consider adding text search indexes on name fields based on your database platform’s capabilities.

Data Types by Platform

Different database platforms use slightly different data type specifications:

Relationships and Constraints

Foreign Key Constraints

Foreign key constraints are enforced in most SQL databases but may need to be handled at the application level in some NoSQL implementations.

Data Integrity Rules

  • All primary keys must be non-null and unique
  • Country names, ISO codes are required
  • State and city names are required
  • Geographic coordinates are required for cities
  • ISO2 codes must be exactly 2 characters
  • ISO3 codes must be exactly 3 characters
  • Phone codes must start with ”+”
  • Latitude must be between -90 and 90
  • Longitude must be between -180 and 180
  • States must belong to valid countries
  • Cities must belong to valid states and countries
  • Countries must belong to valid regions and subregions

Common Queries

Here are some frequently used query patterns:

Next Steps

Installation Guide

Learn how to set up the database in your preferred environment.