Skip to main content

Creating a Database

Creating a SQLite database is mostly a file operation with database semantics.

The important part is not the creation command itself; it is confirming the active file path immediately.

Core Concepts

flowchart LR
A[Choose file path] --> B[sqlite3 path.db]
B --> C[Run quick SQL]
C --> D[Check .databases]
D --> E[Database ready]
ConcernGood habit
Wrong working directoryUse explicit path
Duplicate filenamesKeep project-specific naming
Unsure active DBRun .databases right away

Code Examples

# Create/open a new database by filename.
sqlite3 project_data.db
Expected output
sqlite> prompt opens for project_data.db.
-- Verify the active database file path.
.databases
Expected output
main points to project_data.db (relative or absolute path).

SQLite-Specific Nuances

SQLite Nuance

SQLite has no "CREATE DATABASE" command like some server systems.

Creation is tied to opening a writable file path.

Common Pitfalls / Best Practices

Pitfall

Creating the same filename in multiple directories and assuming they are the same database.

Best Practice

Adopt a clear naming convention, for example app_dev.db, app_test.db, and app_prod.db.

Quick Challenge

Create inventory_dev.db and confirm the main path using .databases.

View Solution
sqlite3 inventory_dev.db
Expected result
.databases shows main attached to inventory_dev.db.