Skip to main content

Opening a Database

Opening a database in SQLite usually means opening a file path.

If the file exists, SQLite uses it. If it does not, SQLite can create it (when writable).

Core Concepts​

ActionCommand
Open existing filesqlite3 app.db
Open in-memory DBsqlite3 ":memory:"
Show attached DBs.databases
# Open a file-backed database from your terminal.
sqlite3 app.db
Expected output
SQLite prompt appears (sqlite>).

Code Examples​

-- Confirm which database file is active.
.databases
Expected output
A row like main: /full/or/relative/path/app.db

SQLite-Specific Nuances​

SQLite Nuance

The active database is usually named main in SQLite.

Additional files can be attached later under other names.

Common Pitfalls / Best Practices​

Pitfall

Running sqlite3 app.db from the wrong directory and accidentally creating a new empty file with the same name.

Best Practice

Use explicit paths (or run .databases) whenever you are unsure which file is open.

Quick Challenge​

Open practice.db, then run .databases and identify the path for main.

View Solution
sqlite3 practice.db
Expected result
Prompt opens; .databases shows main pointing to practice.db.