7.1 Python with SQLite — Complete Database Tutorial
7.1 Python with SQLite
SQLite is a lightweight, file-based relational database that is
included with Python through the built-in
sqlite3 module.
Unlike database servers such as MySQL or PostgreSQL, SQLite does
not require a separate database server for basic applications.
The database is normally stored in a single
.db file.
SQLite provides an excellent starting point for learning relational databases, SQL queries, data persistence, and Python database programming before moving to larger database systems.
1. Learning Objectives
By the end of this lesson, you will be able to:
- Understand SQLite and relational databases.
- Import Python's
sqlite3module. - Create a SQLite database.
- Create database tables.
- Insert records.
- Retrieve records using SQL.
- Filter and sort database records.
- Update existing records.
- Delete records.
- Use parameterized SQL queries.
- Commit and rollback transactions.
- Use primary keys and constraints.
- Work with multiple related tables.
- Use aggregate functions.
- Perform SQL joins.
- Connect SQLite with pandas.
- Build a small database-driven Python application.
2. What Is SQLite?
SQLite is a relational database engine that stores structured data in database files.
A SQLite database can contain multiple tables, indexes, views, and other database objects.
Python Program
|
v
sqlite3 Module
|
v
SQLite Database
|
v
database.db
3. SQLite vs Server-Based Databases
| Feature | SQLite | MySQL / PostgreSQL |
|---|---|---|
| Separate server | Not required | Normally required |
| Storage | Usually a file | Server-managed database |
| Setup | Very simple | More configuration |
| Learning SQL | Excellent | Excellent |
| Small applications | Very suitable | Suitable |
| Large multi-user systems | Limited compared with server databases | Designed for this use |
4. Common SQLite Use Cases
- Desktop applications
- Small web applications
- Prototypes
- Educational projects
- Testing and development
- Local data storage
- Data-analysis experiments
- Embedded applications
- Automation scripts
A Python automation script can collect daily data and store thousands of records in SQLite instead of maintaining a growing collection of Excel files.
5. Import the sqlite3 Module
Python includes the sqlite3 module in its standard
library.
import sqlite3
Therefore, no separate package installation is normally required.
6. Create or Open a SQLite Database
import sqlite3
connection = sqlite3.connect(
"school.db"
)
If school.db does not exist, SQLite creates it.
If it already exists, SQLite opens the existing database.
SQLite databases are persistent. Closing the Python program does not delete the stored records.
7. Connection and Cursor
Two objects are commonly used when working with SQLite:
- Connection: Represents the connection to the database.
- Cursor: Executes SQL statements and retrieves results.
import sqlite3
connection = sqlite3.connect(
"school.db"
)
cursor = connection.cursor()
8. Create a Database Table
SQL is used to define the structure of a relational table.
sql = """
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER,
course TEXT
)
"""
cursor.execute(sql)
connection.commit()
The IF NOT EXISTS clause prevents an error if the
table has already been created.
9. Understanding the Table Structure
| Column | Data Type | Constraint |
|---|---|---|
| id | INTEGER | PRIMARY KEY |
| name | TEXT | NOT NULL |
| age | INTEGER | Optional |
| course | TEXT | Optional |
10. Why Is commit() Important?
Database modifications generally need to be committed so that the transaction becomes persistent.
connection.commit()
Operations such as INSERT,
UPDATE, and DELETE should normally be
committed after successful execution.
11. Insert a Record
sql = """
INSERT INTO students
(name, age, course)
VALUES (?, ?, ?)
"""
cursor.execute(
sql,
(
"Alex Morgan",
20,
"Computer Science"
)
)
connection.commit()
The question marks are parameter placeholders. This is preferable to constructing SQL by directly concatenating user input.
12. Insert Multiple Records
students = [
(
"Alex Morgan",
20,
"Computer Science"
),
(
"Emma Carter",
21,
"Data Science"
),
(
"Noah Wilson",
19,
"Information Technology"
)
]
cursor.executemany(
"""
INSERT INTO students
(name, age, course)
VALUES (?, ?, ?)
""",
students
)
connection.commit()
executemany() is convenient when the same SQL
operation needs to be performed for multiple records.
13. Retrieve All Records
cursor.execute(
"SELECT * FROM students"
)
rows = cursor.fetchall()
for row in rows:
print(row)
fetchall() returns all available result rows.
14. Retrieve One Record
cursor.execute(
"SELECT * FROM students"
)
row = cursor.fetchone()
print(row)
fetchone() retrieves one row from the current result
set.
15. Filter Records with WHERE
cursor.execute(
"""
SELECT *
FROM students
WHERE age > ?
""",
(20,)
)
rows = cursor.fetchall()
for row in rows:
print(row)
16. Sort Records with ORDER BY
cursor.execute(
"""
SELECT *
FROM students
ORDER BY age DESC
"""
)
rows = cursor.fetchall()
for row in rows:
print(row)
DESC sorts from highest to lowest, while
ASC sorts from lowest to highest.
17. Limit the Number of Results
cursor.execute(
"""
SELECT *
FROM students
ORDER BY age DESC
LIMIT 2
"""
)
rows = cursor.fetchall()
This retrieves only the first two records after sorting.
18. Update a Record
cursor.execute(
"""
UPDATE students
SET course = ?
WHERE id = ?
""",
(
"Artificial Intelligence",
1
)
)
connection.commit()
Be careful when writing UPDATE statements.
Forgetting the WHERE condition can update every
row in the table.
19. Delete a Record
cursor.execute(
"""
DELETE FROM students
WHERE id = ?
""",
(3,)
)
connection.commit()
As with UPDATE, always carefully verify the
WHERE condition.
20. Delete a Table
cursor.execute(
"""
DROP TABLE IF EXISTS students
"""
)
connection.commit()
DROP TABLE removes the table and its records.
Use it carefully, particularly with production data.
21. Close the Database Connection
connection.close()
Close database connections when they are no longer required.
22. Use a Context Manager
A context manager can make transaction handling safer and cleaner.
import sqlite3
with sqlite3.connect(
"school.db"
) as connection:
cursor = connection.cursor()
cursor.execute(
"""
INSERT INTO students
(name, age, course)
VALUES (?, ?, ?)
""",
(
"Olivia Brown",
22,
"Data Science"
)
)
The connection context manager commits successfully completed transactions and rolls back when an exception causes the block to fail.
23. Parameterized SQL Queries
Never construct SQL queries by directly inserting untrusted input into SQL strings.
Avoid:
name = input(
"Enter name: "
)
sql = (
"SELECT * FROM students "
+ "WHERE name = '"
+ name
+ "'"
)
cursor.execute(sql)
Instead, use parameters:
name = input(
"Enter name: "
)
cursor.execute(
"""
SELECT *
FROM students
WHERE name = ?
""",
(name,)
)
Parameterized queries help prevent SQL injection and correctly handle values containing special characters.
24. Understanding SQL Injection
SQL injection occurs when untrusted input is improperly incorporated into SQL statements and changes the intended meaning of the query.
The solution is not simply to remove a few special characters. Use the database driver's parameter-binding mechanism.
cursor.execute(
"""
SELECT *
FROM students
WHERE name = ?
""",
(user_input,)
)
25. Primary Keys
A primary key uniquely identifies a row in a table.
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER,
course TEXT
)
Here, id acts as the unique identifier for each
student record.
26. NOT NULL Constraint
NOT NULL prevents a column from containing
NULL values.
name TEXT NOT NULL
This is useful when a particular field is mandatory.
27. UNIQUE Constraint
A UNIQUE constraint prevents duplicate values in a
column.
CREATE TABLE users (
id INTEGER PRIMARY KEY,
username TEXT UNIQUE,
email TEXT UNIQUE
)
28. DEFAULT Values
CREATE TABLE tasks (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
status TEXT DEFAULT 'Pending'
)
If a status is not supplied during insertion, SQLite can use the defined default value.
29. Common SQLite Storage Classes
| Storage Class | Typical Use |
|---|---|
| NULL | Missing or unknown value |
| INTEGER | Whole numbers |
| REAL | Floating-point numbers |
| TEXT | Strings |
| BLOB | Binary data |
30. Aggregate Functions
SQL provides functions for calculating summaries from multiple records.
cursor.execute(
"""
SELECT
COUNT(*),
AVG(age),
MIN(age),
MAX(age)
FROM students
"""
)
result = cursor.fetchone()
print(result)
Common aggregate functions include:
COUNT()SUM()AVG()MIN()MAX()
31. GROUP BY
GROUP BY groups records before aggregate calculations
are performed.
cursor.execute(
"""
SELECT
course,
COUNT(*) AS total_students
FROM students
GROUP BY course
"""
)
rows = cursor.fetchall()
for row in rows:
print(row)
32. HAVING
HAVING filters grouped results.
cursor.execute(
"""
SELECT
course,
COUNT(*) AS total_students
FROM students
GROUP BY course
HAVING COUNT(*) > 1
"""
)
Remember the distinction:
WHEREfilters rows before grouping.HAVINGfilters groups after aggregation.
33. Working with Multiple Tables
Relational databases normally divide related information into separate tables.
students
----------------
id
name
course_id
courses
----------------
id
course_name
This avoids unnecessary repetition and creates relationships between entities.
34. Foreign Keys
A foreign key references a key in another table.
CREATE TABLE courses (
id INTEGER PRIMARY KEY,
course_name TEXT NOT NULL
)
CREATE TABLE students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
course_id INTEGER,
FOREIGN KEY (
course_id
)
REFERENCES courses(id)
)
35. Enable Foreign-Key Enforcement
When using SQLite, applications should explicitly enable foreign key enforcement when they rely on foreign-key constraints.
connection.execute(
"PRAGMA foreign_keys = ON"
)
This should be done for each database connection where foreign-key enforcement is required.
36. INNER JOIN
A join combines related records from multiple tables.
cursor.execute(
"""
SELECT
students.name,
courses.course_name
FROM students
INNER JOIN courses
ON students.course_id =
courses.id
"""
)
rows = cursor.fetchall()
for row in rows:
print(row)
37. Database Transactions
A transaction groups related database operations into a logical unit of work.
try:
cursor.execute(
"""
INSERT INTO students
(name, age, course)
VALUES (?, ?, ?)
""",
(
"Liam Davis",
20,
"Computer Science"
)
)
cursor.execute(
"""
INSERT INTO students
(name, age, course)
VALUES (?, ?, ?)
""",
(
"Mia Taylor",
21,
"Data Science"
)
)
connection.commit()
except Exception:
connection.rollback()
raise
If an operation fails before the commit, the application can roll back the transaction.
38. commit() vs rollback()
| Method | Purpose |
|---|---|
commit() |
Save the transaction's changes |
rollback() |
Undo uncommitted transaction changes |
39. Access Columns by Name
By default, SQLite query results are returned as tuples.
cursor.execute(
"SELECT * FROM students"
)
row = cursor.fetchone()
print(row[0])
print(row[1])
A row factory can provide more readable access:
connection.row_factory = (
sqlite3.Row
)
cursor = connection.cursor()
cursor.execute(
"SELECT * FROM students"
)
row = cursor.fetchone()
print(
row["name"]
)
print(
row["course"]
)
40. Retrieve the Generated Primary Key
cursor.execute(
"""
INSERT INTO students
(name, age, course)
VALUES (?, ?, ?)
""",
(
"James Anderson",
20,
"Data Science"
)
)
student_id = (
cursor.lastrowid
)
connection.commit()
print(
student_id
)
lastrowid is useful when a newly inserted row's
identifier is required for subsequent operations.
41. Read SQLite Data with pandas
SQLite becomes particularly useful for data science when combined with pandas.
import pandas as pd
query = """
SELECT *
FROM students
"""
df = pd.read_sql_query(
query,
connection
)
print(df)
This converts SQL query results directly into a pandas DataFrame.
42. SQL Filtering Before DataFrame Analysis
query = """
SELECT
name,
age,
course
FROM students
WHERE age > ?
"""
df = pd.read_sql_query(
query,
connection,
params=(20,)
)
print(df)
Filtering in SQL can reduce the amount of data transferred into Python.
43. Write a DataFrame to SQLite
df = pd.DataFrame(
{
"name": [
"Alex Morgan",
"Emma Carter"
],
"age": [
20,
21
],
"course": [
"Data Science",
"Computer Science"
]
}
)
df.to_sql(
"students",
connection,
if_exists="replace",
index=False
)
if_exists="replace".
It replaces the existing table. For historical data, consider
whether append is more appropriate.
44. Append Data to an Existing Table
df.to_sql(
"students",
connection,
if_exists="append",
index=False
)
append adds the DataFrame's rows to the existing
table.
45. Inspect Tables in the Database
cursor.execute(
"""
SELECT name
FROM sqlite_master
WHERE type = 'table'
ORDER BY name
"""
)
tables = cursor.fetchall()
for table in tables:
print(table)
46. Inspect a Table's Schema
cursor.execute(
"""
PRAGMA table_info(students)
"""
)
columns = cursor.fetchall()
for column in columns:
print(column)
This is useful when developing scripts that need to understand an existing SQLite database.
47. Database Indexes
An index can improve the performance of queries that frequently search or sort using particular columns.
cursor.execute(
"""
CREATE INDEX IF NOT EXISTS
idx_students_course
ON students(course)
"""
)
connection.commit()
Indexes can make certain reads faster, but they also consume storage and can add overhead to data modifications.
48. Mini Project — Student Database
We will build a simple Python application that stores student information in SQLite.
Database Design
students
--------------------------------
id
name
age
course
email
49. Step 1 — Create the Database
import sqlite3
connection = sqlite3.connect(
"student_database.db"
)
cursor = connection.cursor()
50. Step 2 — Create the Students Table
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER,
course TEXT,
email TEXT UNIQUE
)
"""
)
connection.commit()
51. Step 3 — Insert Student Records
students = [
(
"Alex Morgan",
20,
"Computer Science",
"alex@example.com"
),
(
"Emma Carter",
21,
"Data Science",
"emma@example.com"
),
(
"Noah Wilson",
19,
"Information Technology",
"noah@example.com"
)
]
cursor.executemany(
"""
INSERT OR IGNORE INTO students
(name, age, course, email)
VALUES (?, ?, ?, ?)
""",
students
)
connection.commit()
52. Step 4 — Display Students
cursor.execute(
"""
SELECT
id,
name,
age,
course,
email
FROM students
ORDER BY name
"""
)
rows = cursor.fetchall()
for row in rows:
print(row)
53. Step 5 — Search Students
search_term = input(
"Enter student name: "
)
cursor.execute(
"""
SELECT *
FROM students
WHERE name LIKE ?
""",
(
f"%{search_term}%",
)
)
rows = cursor.fetchall()
for row in rows:
print(row)
The % wildcard allows the search term to match part of
the name.
54. Step 6 — Update Student Information
student_id = 1
new_course = (
"Artificial Intelligence"
)
cursor.execute(
"""
UPDATE students
SET course = ?
WHERE id = ?
""",
(
new_course,
student_id
)
)
connection.commit()
55. Step 7 — Delete a Student
student_id = 3
cursor.execute(
"""
DELETE FROM students
WHERE id = ?
""",
(student_id,)
)
connection.commit()
56. Complete Mini Project
import sqlite3
DATABASE = (
"student_database.db"
)
def create_database():
connection = (
sqlite3.connect(
DATABASE
)
)
cursor = (
connection.cursor()
)
cursor.execute(
"""
CREATE TABLE IF NOT EXISTS students (
id INTEGER PRIMARY KEY,
name TEXT NOT NULL,
age INTEGER,
course TEXT,
email TEXT UNIQUE
)
"""
)
connection.commit()
connection.close()
def add_student(
name,
age,
course,
email
):
with sqlite3.connect(
DATABASE
) as connection:
connection.execute(
"""
INSERT INTO students
(name, age, course, email)
VALUES (?, ?, ?, ?)
""",
(
name,
age,
course,
email
)
)
def get_students():
with sqlite3.connect(
DATABASE
) as connection:
cursor = (
connection.execute(
"""
SELECT *
FROM students
ORDER BY name
"""
)
)
return cursor.fetchall()
def update_course(
student_id,
course
):
with sqlite3.connect(
DATABASE
) as connection:
connection.execute(
"""
UPDATE students
SET course = ?
WHERE id = ?
""",
(
course,
student_id
)
)
def delete_student(
student_id
):
with sqlite3.connect(
DATABASE
) as connection:
connection.execute(
"""
DELETE FROM students
WHERE id = ?
""",
(student_id,)
)
create_database()
add_student(
"Alex Morgan",
20,
"Computer Science",
"alex@example.com"
)
add_student(
"Emma Carter",
21,
"Data Science",
"emma@example.com"
)
update_course(
1,
"Artificial Intelligence"
)
for student in get_students():
print(student)
57. CRUD Operations
The four fundamental database operations are commonly represented by the acronym CRUD.
| CRUD | SQL | Purpose |
|---|---|---|
| Create | INSERT | Add records |
| Read | SELECT | Retrieve records |
| Update | UPDATE | Modify records |
| Delete | DELETE | Remove records |
58. Essential SQL Commands
| Command | Purpose |
|---|---|
CREATE TABLE |
Create a table |
INSERT |
Add records |
SELECT |
Retrieve records |
WHERE |
Filter records |
ORDER BY |
Sort results |
GROUP BY |
Group records |
HAVING |
Filter groups |
JOIN |
Combine related tables |
UPDATE |
Modify records |
DELETE |
Remove records |
59. SQLite vs Excel for Automation
Both Excel and SQLite are useful, but they solve different problems.
| Requirement | Excel | SQLite |
|---|---|---|
| Manual viewing | Excellent | Requires a database tool or application |
| Structured relational data | Limited | Excellent |
| SQL queries | Not native | Native |
| Data persistence | Yes | Yes |
| Python integration | Excellent | Excellent |
| Relational constraints | Limited | Supported |
60. SQLite in a Data Science Workflow
SQLite Database
↓
SQL Query
↓
pandas DataFrame
↓
Data Cleaning
↓
EDA
↓
Visualization
↓
Report
This workflow connects database skills with the NumPy, pandas, visualization, and EDA concepts learned earlier.
61. SQLite in an Automation Workflow
External Data
↓
Python Automation
↓
Validation
↓
SQLite Database
↓
SQL Analysis
↓
pandas
↓
Excel / PDF / Email
SQLite therefore provides a persistent storage layer between data collection and reporting.
62. SQLite Best Practices
- Use parameterized queries.
- Commit changes deliberately.
- Close connections when finished.
- Use transactions for related operations.
- Validate external input.
- Define appropriate constraints.
- Use meaningful table and column names.
- Create indexes for appropriate frequently queried columns.
- Back up important database files.
- Avoid storing unnecessary sensitive information.
- Separate database logic from application logic.
- Test database operations independently.
63. Common Mistakes
| Mistake | Problem | Better Approach |
|---|---|---|
| Not committing changes | Changes may not persist | Commit successful transactions |
| Building SQL with string concatenation | Security and correctness problems | Use parameters |
| Forgetting WHERE in UPDATE | Every row may be modified | Verify the condition |
| Forgetting WHERE in DELETE | Every row may be deleted | Verify the condition |
| Never backing up important data | Recovery becomes difficult | Maintain appropriate backups |
| One giant database function | Difficult to maintain | Separate responsibilities |
64. Python SQLite Interview Questions
Q1. What is SQLite?
View Answer
SQLite is a lightweight relational database engine that stores database information in a file and does not normally require a separate database server.
Q2. Which Python module is used to work with SQLite?
View Answer
Python provides the built-in sqlite3 module.
Q3. What is a cursor?
View Answer
A cursor is an object used to execute SQL statements and retrieve query results.
Q4. What does commit() do?
View Answer
It commits the current transaction so that successful database modifications become persistent.
Q5. Why should parameterized queries be used?
View Answer
They separate SQL instructions from data values and help protect against SQL injection while correctly handling special characters.
Q6. What does fetchall() return?
View Answer
It returns all remaining rows from the current query result.
Q7. How can SQLite data be loaded into a pandas DataFrame?
View Answer
Functions such as
pandas.read_sql_query() can execute SQL
against a SQLite connection and return the results as a
DataFrame.
Q8. What is a primary key?
View Answer
A primary key uniquely identifies a row in a database table.
Q9. What is a foreign key?
View Answer
A foreign key establishes a relationship by referencing a key in another table.
Q10. What is the difference between WHERE and HAVING?
View Answer
WHERE filters individual rows before grouping, while HAVING filters groups after aggregation.
65. Examination Questions — MCQs
Q1. Which module provides SQLite support in Python?
- sqlite3
- sqlpython
- pysqlite-core
- database
Answer: A
Q2. Which SQL command retrieves records?
- INSERT
- SELECT
- UPDATE
- DELETE
Answer: B
Q3. Which SQL command adds records?
- INSERT
- SELECT
- READ
- ADDROW
Answer: A
Q4. Which method saves a transaction?
- save()
- commit()
- store()
- persist()
Answer: B
Q5. Which method retrieves all query rows?
- fetchall()
- getall()
- readall()
- rows()
Answer: A
Q6. Which constraint uniquely identifies a row?
- DEFAULT
- NOT NULL
- PRIMARY KEY
- CHECK
Answer: C
Q7. Which SQL clause filters rows?
- WHERE
- HAVING
- GROUP
- FILTER BY
Answer: A
Q8. Which pandas function can read SQL query results into a DataFrame?
- pd.read_sql_query()
- pd.read_database_file()
- pd.import_sql()
- pd.sqlite_read()
Answer: A
Q9. What should be used instead of string concatenation for untrusted SQL values?
- Parameterized queries
- HTML encoding
- Comments
- String formatting
Answer: A
Q10. Which SQL operation combines related tables?
- JOIN
- MERGEFILE
- CONNECTROW
- COMBINE
Answer: A
66. Practical Examination Tasks
Task 1 — Database Creation
Create a SQLite database named
inventory.db and create a table named
products.
Task 2 — CRUD Operations
Implement functions to insert, retrieve, update, and delete product records.
Task 3 — Search
Write a parameterized query that searches products by name.
Task 4 — Aggregation
Calculate the number of products and the average product price.
Task 5 — pandas Integration
Load the SQLite table into a pandas DataFrame and display summary statistics.
Task 6 — Automation
Create a Python script that stores daily collected data in SQLite and generates a CSV or Excel report.
67. Mini Project — Automated Data Store
Extend the automation concepts from the previous module.
Public Data
↓
Python requests
↓
Validation
↓
SQLite
↓
pandas
↓
Excel
↓
PDF
↓
Email
SQLite acts as the persistent database layer between the data collection process and the reporting system.
68. Coding Challenge
Build a Product Inventory Database with the following columns:
products
--------------------------------
id
name
category
price
quantity
created_at
Requirements
- Create the SQLite database.
- Create the products table.
- Insert at least ten products.
- Display all products.
- Search products by category.
- Find products costing more than a specified amount.
- Update product quantities.
- Delete a product.
- Calculate total inventory value.
- Load the data into pandas.
- Export the DataFrame to Excel.
69. Real-World Interview Scenario
Scenario:
A Python automation program collects thousands of records every day. The current system stores each day's data in a separate Excel file. Searching across six months of data has become slow and difficult. How would you redesign the system?
Expected Approach
- Use SQLite or an appropriate database for persistent storage.
- Design normalized tables where appropriate.
- Add primary keys and relevant constraints.
- Insert validated records into the database.
- Use SQL queries for filtering and aggregation.
- Load selected results into pandas for analysis.
- Generate Excel/PDF reports only when required.
- Schedule the collection process.
- Maintain backups and logs.
70. Python SQLite Quick Reference
| Operation | Python / SQL |
|---|---|
| Import SQLite | import sqlite3 |
| Connect | sqlite3.connect() |
| Create cursor | connection.cursor() |
| Execute SQL | cursor.execute() |
| Multiple operations | cursor.executemany() |
| Get one row | fetchone() |
| Get all rows | fetchall() |
| Save changes | commit() |
| Undo uncommitted changes | rollback() |
| Close connection | close() |
| DataFrame from SQL | pd.read_sql_query() |
| DataFrame to SQLite | df.to_sql() |
71. Self-Assessment Checklist
You should now be able to:
- ☐ Explain what SQLite is.
- ☐ Explain the difference between SQLite and a server-based database.
- ☐ Create a SQLite database with Python.
- ☐ Create tables.
- ☐ Define primary keys.
- ☐ Use constraints.
- ☐ Insert records.
- ☐ Retrieve records.
- ☐ Filter and sort records.
- ☐ Update records safely.
- ☐ Delete records safely.
- ☐ Use parameterized queries.
- ☐ Explain SQL injection.
- ☐ Use transactions.
- ☐ Use
commit()androllback(). - ☐ Work with multiple related tables.
- ☐ Use foreign keys.
- ☐ Perform SQL joins.
- ☐ Use aggregate functions.
- ☐ Use SQLite with pandas.
- ☐ Build a database-driven Python application.
Python's built-in sqlite3 module provides a
practical bridge between Python programming, SQL, databases,
automation, and data science.
Once you understand SQLite, the same core concepts—tables, relationships, queries, transactions, constraints, and parameterized SQL—provide a strong foundation for working with larger relational database systems.