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
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, etc.)
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)
Geographical latitude coordinate
Geographical longitude coordinate
Wikidata identifier for additional reference data
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: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
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