Skip to main content

Deleting a Database

Deleting a SQLite database means deleting its file from disk.

This is simple but irreversible without backups, so verification is essential.

Core Concepts

flowchart TD
A[Need to remove DB] --> B[Confirm path + backup]
B --> C[Close active connections]
C --> D[Delete file in OS]
D --> E[Verify file no longer exists]
Safety checkWhy
Confirm exact file pathPrevent deleting wrong database
Ensure backup existsRecovery option
Close app/CLI connectionsAvoid lock and partial cleanup issues

Code Examples

# Linux/macOS: delete database file.
rm app_dev.db
Expected output
No output on success; file is removed.
# Windows PowerShell: delete database file.
Remove-Item "app_dev.db"
Expected output
No output on success; file is removed.

SQLite-Specific Nuances

SQLite Nuance

There is no SQL DROP DATABASE in SQLite because a database is usually a single file, managed by the OS.

Common Pitfalls / Best Practices

Pitfall

Using broad delete patterns in the wrong directory, such as deleting multiple .db files unintentionally.

Best Practice

List files first, then delete a single explicit filename.

Quick Challenge

Before deleting scratch.db, write down:

  1. Full path
  2. Backup location
  3. Confirmation that no process has it open
View Solution

A safe deletion checklist is complete only when all three are confirmed.

Then delete using an explicit command like:

rm /full/path/to/scratch.db
Expected result
File is removed; reopening same name later creates a fresh empty database.