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.Unique identifier for the region (Primary Key)
Official name of the region (e.g., “Europe”, “Asia”, “Africa”)
Wikidata identifier for additional reference data
Record creation timestamp
Last modification timestamp
2. Subregions Table
Subdivisions of regions providing more granular geographical classification.Unique identifier for the subregion (Primary Key)
Official name of the subregion (e.g., “Western Europe”, “Southern Asia”)
Foreign key reference to the parent region
Wikidata identifier for additional reference data
Record creation timestamp
Last modification timestamp
3. Countries Table
Complete country information with ISO codes, economic data, and geographical coordinates.Unique identifier for the country (Primary Key)
Official English name of the country
ISO 3166-1 alpha-3 code (e.g., “USA”, “IND”, “GBR”)
ISO 3166-1 alpha-2 code (e.g., “US”, “IN”, “GB”)
ISO 3166-1 numeric code
International dialing code (e.g., “+1”, “+91”, “+44”)
Name of the country’s capital city
ISO 4217 currency code (e.g., “USD”, “EUR”, “INR”)
Full name of the currency
Currency symbol (e.g., ”$”, ”€”, ”₹”)
Top-level domain (e.g., “.us”, “.in”, “.uk”)
Native name of the country in local language/script
Region name (denormalized for quick access)
Subregion name (denormalized for quick access)
Foreign key reference to the regions table
Foreign key reference to the subregions table
Demonym for country citizens (e.g., “American”, “Indian”, “British”)
Geographical latitude coordinate of country center
Geographical longitude coordinate of country center
Unicode emoji flag representation
Unicode code points for the flag emoji
Country population (may be null for territories with no dedicated census)
Gross domestic product in USD billions (approximate)
Total area in square kilometres
Human-readable postal code format pattern (e.g.,
##### for US zip codes)Regular expression for validating postal codes for this country
JSON array of timezone objects for the country. Each object contains
zoneName, gmtOffset, gmtOffsetName, abbreviation, and tzName.JSON object of country name translations keyed by locale code (e.g.,
"fr": "États-Unis", "de": "Vereinigte Staaten"). 19 languages supported.Wikidata identifier for cross-referencing additional metadata
4. States Table
Administrative divisions within countries (states, provinces, regions, etc.).Unique identifier for the state (Primary Key)
Official name of the state/province/region
Foreign key reference to the parent country
ISO 2-letter country code for quick reference
Country name (denormalized for performance)
Official state/province code when available
Type of administrative division (state, province, region, municipality, etc.)
FIPS (Federal Information Processing Standards) code, primarily used for US states
ISO 3166-2 subdivision code (e.g.,
US-CA, IN-MH, GB-ENG)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.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.
State name in the local/native language and script
Primary IANA timezone identifier for the state (e.g.,
America/Los_Angeles)JSON object of state name translations keyed by locale code
State population estimate
Wikidata identifier for cross-referencing additional metadata
Geographical latitude coordinate of state center
Geographical longitude coordinate of state center
5. Cities Table
Cities, towns, and other populated places within states/countries.Unique identifier for the city (Primary Key)
Official name of the city/town
Foreign key reference to the parent state
State code for quick reference
State name (denormalized for performance)
Foreign key reference to the country
ISO 2-letter country code for quick reference
Country name (denormalized for performance)
Place classification inherited from GeoNames (e.g.,
city, town, adm2, county). See the city types reference for all 35 values and filtering guidance.Administrative hierarchy level within the state, mirroring the state-level structure where applicable
Foreign key to the parent city row for nested subdivisions (e.g., a district within a city)
City name in the local/native language and script
City population estimate
IANA timezone identifier for the city (e.g.,
America/Los_Angeles)JSON object of city name translations keyed by locale code
Geographical latitude coordinate
Geographical longitude coordinate
Wikidata identifier for additional reference data
6. Postcodes Table
844,248 postal codes across 125 countries with type classification and source tracking.Unique identifier for the postcode record (Primary Key)
The postal / ZIP code string (e.g.,
90210, SW1A 1AA, 110001)ISO 3166-1 alpha-2 country code linking to the countries table
Granularity of the postcode. One of:
full— complete postcode identifying a specific delivery point or small areaoutward— first part of a UK-style postcode identifying the postal districtsector— intermediate granularity within a districtdistrict— broadest level, covering an entire postal district
Data source attribution for the postcode record
Name of the locality or area associated with this postcode
Wikidata identifier for cross-referencing
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 theid 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:- MySQL
- PostgreSQL
- SQLite
Relationships and Constraints
Foreign Key Constraints
Data Integrity Rules
Required Fields
Required Fields
- 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
Format Validation
Format Validation
- 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
Referential Integrity
Referential Integrity
- 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.