What Is SQLite?
SQLite is a lightweight relational database system that stores an entire database in a file. Unlike many database systems, it does not require a separate database server running in the background.
SQLite is an embedded relational database
SQLite is a relational database management system designed to be embedded directly inside applications.
A complete SQLite database is commonly stored in a single file on disk.
Applications interact with that file using SQL commands such as SELECT, INSERT, UPDATE and DELETE.
A database can be just one file
A SQLite database might look like this:
Inside that file could be several tables:
The application can open the database file and query those tables directly.
SQLite does not need a separate database server
Systems such as MySQL and PostgreSQL normally run as separate database server processes.
Applications connect to those servers over a local connection or network connection.
SQLite works differently.
The application accesses the database through the SQLite library rather than contacting a separate database server.
SQLite uses SQL
SQL stands for Structured Query Language.
SQL is used to create, read, update and delete data stored in relational databases.
This query asks SQLite to return all rows from the customers table.
SQLite stores data in tables
A customer table might contain:
| id | name | |
|---|---|---|
| 1 | Alice | alice@example.com |
| 2 | Ben | ben@example.com |
| 3 | Carla | carla@example.com |
Each row represents a record, while each column represents a particular type of information.
Tables can be created with SQL
This creates a table containing three columns:
Data can be inserted
This adds a new row to the customers table.
Data can be retrieved
A condition can also be added:
This retrieves the customer whose ID is 1.
Existing data can be changed
This changes the email address associated with the selected row.
Rows can be deleted
The matching row is removed from the table.
These operations are often called CRUD
Create
Add new records to the database.
Read
Retrieve existing information.
Update
Change existing records.
Delete
Remove records from the database.
SQLite is a relational database
Relational databases can connect information stored across different tables.
For example:
The customer_id value connects the orders to Alice's customer record.
SQL can combine related tables
The database can use the relationship between the tables to combine the relevant information.
SQLite databases can use different file extensions
You may encounter files such as:
The extension does not fundamentally determine whether the file is a SQLite database. It is mainly a naming convention.
SQLite can store several kinds of values
| Storage class | Purpose |
|---|---|
| NULL | No value |
| INTEGER | Whole numbers |
| REAL | Floating-point numbers |
| TEXT | Text strings |
| BLOB | Binary data |
SQLite is often embedded inside applications
Software can include SQLite as part of the application itself.
The user may never even realise that a SQLite database is being used.
SQLite databases are highly portable
Because a database can be stored in a single file, it can be straightforward to copy, back up or move.
The database can sit directly alongside the application files.
SQLite is very different from CSV
| CSV | SQLite |
|---|---|
| Plain-text file | Database file |
| Usually one table | Can contain many tables |
| No SQL engine | Supports SQL queries |
| Limited relationships | Relational structure |
| Simple data exchange | Application data storage |
SQLite and MySQL use different architectures
| SQLite | MySQL |
|---|---|
| Embedded database | Database server |
| Database commonly stored in one file | Server manages database storage |
| No separate server required | Requires database server software |
| Excellent for local and embedded use | Common for networked applications |
SQLite is not designed for every database workload
SQLite is extremely useful when simplicity and local storage are important.
A dedicated database server such as PostgreSQL or MySQL may be more appropriate when an application requires many simultaneous writers, centralised access, extensive server administration or large multi-user workloads.
SQLite is not simply a smaller MySQL. Its architecture is deliberately different. It is designed to provide a database engine directly inside an application.
SQLite supports transactions
A transaction allows several database operations to be treated as one logical unit.
Transactions help protect data from being left in an incomplete state if an operation fails.
SQLite supports ACID transactions
Atomicity
A transaction is completed as a unit or rolled back.
Consistency
Database rules can help preserve valid states.
Isolation
Transactions are managed to avoid unsafe interference.
Durability
Committed changes are designed to survive failures.
Indexes can improve query performance
An index can allow the database to find certain values more efficiently instead of examining every row.
Many programming languages can use SQLite
SQLite can be used from application code
For example, Python includes support for SQLite:
The program opens the database file, executes a query and retrieves the results.
What is SQLite used for?
Why is SQLite useful?
Simple
No separate database server needs to be configured.
Portable
An entire database can commonly be stored in one file.
Lightweight
The database engine can be embedded directly inside an application.
Powerful
It still provides SQL, transactions, indexes, relationships and many database features.
A SQLite database is more than an ordinary data file
A CSV file stores rows of text.
A JSON file stores structured text.
A SQLite file contains a database managed by an actual database engine.
That distinction is important.
A database inside one file.
SQLite is an embedded relational database system that provides SQL, tables, relationships, transactions and indexes without requiring a separate database server. Its simplicity and portability make it useful for mobile apps, desktop software, local tools, prototypes and many other applications.