Skip to main content

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​

Verification stepWhy it matters
Use full or project-relative pathAvoid wrong directory issues
Run .databasesConfirms active file
Optionally inspect .tablesSanity-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:

  • .databases to validate file path
  • .tables to validate expected objects