Difference Between .sql and .db
A comprehensive guide to SQL scripts versus binary database files.
The .sql File
A .sql file is usually a text file containing SQL commands.
It may contain:
- CREATE TABLE
- INSERT
- UPDATE
- SELECT
- ALTER
- Database schema definitions
- Backup scripts
Example
CREATE TABLE users (
id INTEGER PRIMARY KEY,
name TEXT
);
INSERT INTO users VALUES (1, 'Alice');
Characteristics
- Human-readable
- Plain text
- Can be opened in any text editor
- Used for backups, migrations, exports/imports
Think of it as: "Instructions for building or modifying a database."
Need to test your SQL?
Use our Interactive SQL Simulator to run commands and visualize your .db output instantly.
Launch SQL Tool The .db File
A .db file is usually the actual database storage file.
Commonly:
- SQLite databases
- Binary format
- Stores real data, indexes, and tables internally
You generally cannot read it directly in a text editor.
Examples
- app.db
- users.db
- database.db
Characteristics
- Binary/internal format
- Contains actual stored records
- Used directly by database engines
- Efficient for querying and storage
Think of it as: "The actual database itself."
Example Workflow
Export Database → SQL
sqlite3 app.db .dump > backup.sql
This creates backup.sql, containing text instructions recreating the DB.
Restore SQL → Database
sqlite3 new.db < backup.sql
This creates new.db, a working binary database file.
Common Database Formats
| Extension | Meaning |
|---|---|
| .sql | SQL script |
| .db | Generic database file |
| .sqlite | SQLite database |
| .mdb | Microsoft Access DB |
| .sqlite3 | SQLite v3 DB |
Summary
| .sql | .db |
|---|---|
| Text instructions | Actual stored database |
| Human-readable | Usually binary |
| Portable script | Database engine file |
| Used to create/modify DB | Used to store/query data |