Complete guide to installing the Countries States Cities database in SQLite for lightweight, embedded applications
SQLite is a lightweight, file-based database that requires no separate server process. It’s perfect for mobile applications, prototypes, and embedded systems. This guide covers installing the Countries States Cities database in SQLite.
SQLite installation is the fastest option, typically taking less than 1 minute with approximately 50MB file size.
SQLite databases are self-contained files that don’t require a separate server installation, making them ideal for development and embedded applications.
This creates a new SQLite database file named world.db in your current directory.
2
Import SQL File
Copy
Ask AI
.read sqlite/world.sql
SQLite import is typically the fastest due to its lightweight nature and single-file architecture.
3
Verify Installation
Copy
Ask AI
-- List all tables.tables-- Check table schema.schema countries-- Count records in each tableSELECT 'countries' as table_name, COUNT(*) as count FROM countriesUNION ALLSELECT 'states', COUNT(*) FROM states UNION ALLSELECT 'cities', COUNT(*) FROM cities;
-- List all tables.tables-- Show table schemas.schema countries.schema states.schema cities-- Get table infoPRAGMA table_info(countries);PRAGMA table_info(states); PRAGMA table_info(cities);
-- Essential indexes for query performanceCREATE INDEX IF NOT EXISTS idx_countries_iso2 ON countries(iso2);CREATE INDEX IF NOT EXISTS idx_countries_iso3 ON countries(iso3);CREATE INDEX IF NOT EXISTS idx_countries_region ON countries(region);CREATE INDEX IF NOT EXISTS idx_states_country_id ON states(country_id);CREATE INDEX IF NOT EXISTS idx_states_name ON states(name);CREATE INDEX IF NOT EXISTS idx_states_country_name ON states(country_name);CREATE INDEX IF NOT EXISTS idx_cities_country_id ON cities(country_id);CREATE INDEX IF NOT EXISTS idx_cities_state_id ON cities(state_id);CREATE INDEX IF NOT EXISTS idx_cities_name ON cities(name);CREATE INDEX IF NOT EXISTS idx_cities_coordinates ON cities(latitude, longitude);CREATE INDEX IF NOT EXISTS idx_cities_country_name ON cities(country_name);
# SQLite databases can be backed up by copying the filecp world.db world_backup_$(date +%Y%m%d).db# Compress backupgzip world_backup_$(date +%Y%m%d).db