Python sqlite3 Cheat Sheet
Cheat Sheet for Python's sqlite3 package and basic queries
Download as .pdf
API: /api/v1/cheatsheet/python-sqlite3-cheat-sheet
Import + Connect
python
⧉
1 2 3 4 | |
Creates or opens: app.db
In-Memory Database
python
⧉
1 | |
Use for: - Testing - Temporary data - Fast disposable DBs
Create Table
python
⧉
1 2 3 4 5 6 7 8 9 | |
Insert One Row
python
⧉
1 2 3 4 5 6 | |
Insert Many Rows
python
⧉
1 2 3 4 5 6 7 8 9 10 11 | |
Select Data
python
⧉
1 2 3 4 5 | |
Fetch Methods
One Row
python
⧉
1 | |
Many Rows
python
⧉
1 | |
All Rows
python
⧉
1 | |
WHERE Clause
python
⧉
1 2 3 4 | |
Update Data
python
⧉
1 2 3 4 5 6 | |
Delete Data
python
⧉
1 2 3 4 5 6 | |
Auto Increment ID
id INTEGER PRIMARY KEY
SQLite auto-generates row IDs.
Last Inserted ID
python
⧉
1 | |
Count Rows
python
⧉
1 2 3 | |
Order Results
sql
⧉
1 | |
Limit Results
sql
⧉
1 | |
Search with LIKE
python
⧉
1 2 3 4 | |
Row as Dictionary
python
⧉
1 2 3 4 5 6 | |
Transactions
python
⧉
1 2 3 4 5 6 7 8 9 | |
Context Manager (Recommended)
python
⧉
1 2 3 4 5 | |
Auto commit / rollback.
Create Index
python
⧉
1 2 3 | |
Drop Table
python
⧉
1 | |
Show Tables
python
⧉
1 2 3 4 5 6 | |
Table Schema
python
⧉
1 2 | |
Join Example
sql
⧉
1 2 3 | |
Parameterized Queries
Safe:
python
⧉
1 2 3 4 | |
Unsafe:
python
⧉
1 2 3 | |
Close Connection
python
⧉
1 | |
Common SQLite Types
| SQLite Type | Meaning |
|---|---|
| INTEGER | Whole numbers |
| REAL | Floating point |
| TEXT | Strings |
| BLOB | Binary data |
| NULL | Missing value |
Mini Example
python
⧉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
Join the Newsletter
Practical insights on Django, backend systems, deployment, architecture, and real-world development — delivered without noise.
Get updates when new guides, learning paths, cheat sheets, and field notes are published.
No spam. Unsubscribe anytime.
There is no third-party involved so don't worry - we won't share your details with anyone.