Opening an Existing Database
Opening existing databases sounds simple, but path mistakes are one of the most common SQLite workflow errors.
This lesson gives you a repeatable checklist.
Core Concepts
flowchart TD
A[Need existing DB] --> B[Use explicit path]
B --> C[Open with sqlite3]
C --> D[Run .databases]
D --> E[Proceed only if path matches expectation]
| Verification step | Why it matters |
|---|---|
| Use full or project-relative path | Avoid wrong directory issues |
Run .databases | Confirms active file |
Optionally inspect .tables | Sanity-check expected content |
Code Examples
# Open an existing database file.
sqlite3 ./data/app.db
| Expected output |
|---|
CLI opens and shows sqlite> prompt. |
-- Confirm opened file and inspect quick metadata.
.databases
.tables
| Expected output |
|---|
.databases path matches target file; .tables shows existing objects (if any). |
SQLite-Specific Nuances
SQLite Nuance
If the specified file path does not exist and is writable, SQLite can create a new empty database with that name.
Common Pitfalls / Best Practices
Pitfall
Misspelling a path and unintentionally creating a brand-new empty database.
Best Practice
For critical workflows, verify both .databases and .tables before running write operations.
Quick Challenge
Open an existing app.db, then prove it's the correct file using two CLI checks.
View Solution
Use:
.databasesto validate file path.tablesto validate expected objects