Why SQLite?
SQLite is called a serverless database because it doesn’t require a separate server process. The entire database lives in a single.db file on your filesystem, making it perfect for development, learning, and embedded use cases.
Key characteristics:
- Zero configuration — no installation server required
- Cross-platform — the same
.dbfile works on Windows, macOS, and Linux - ACID-compliant — your data is safe even if the app crashes
- Fully supports standard SQL syntax
- Not designed for high-concurrency production workloads
- Limited support for
ALTER TABLEcompared with MySQL or PostgreSQL - No built-in user authentication
For learning SQL and building FastAPI backends, SQLite is an ideal choice. When you move to production you can swap it for PostgreSQL or MySQL with minimal code changes.
SQL Command Categories
SQL commands are organized into four groups based on their purpose.
This page covers DDL and DML. DQL (
SELECT) is covered in full on the next page.
SQLite Data Types
SQLite uses a flexible, dynamic type system. The five core storage classes are:Practice: Choosing Data Types
Practice: Choosing Data Types
Choose the appropriate SQLite data type for each attribute:
DDL: Defining Your Schema
CREATE TABLE
UseCREATE TABLE to define a new table and its columns. You specify each column’s name, data type, and any constraints.
Practice: Create a student table
Practice: Create a student table
Write a
CREATE TABLE statement for a student table with student_id, student_name, and email.ALTER TABLE
UseALTER TABLE to modify an existing table without dropping and recreating it.
Add a new column:
Practice: Add a phone column
Practice: Add a phone column
Add a
phone column of type TEXT to the employee table.DROP TABLE
DROP TABLE permanently deletes a table and all of its data.
Practice: Drop the student table
Practice: Drop the student table
DML: Manipulating Your Data
INSERT Statement
UseINSERT INTO to add new rows to a table.
Insert a single row (all columns, in order):
Practice: Insert employee Anitha
Practice: Insert employee Anitha
Insert an employee named Anitha with
employee_id 102 and a salary of ₹55,000 in Bengaluru, assigned to department 2.UPDATE Statement
UseUPDATE to modify existing rows.
Practice: Raise Rahul's salary
Practice: Raise Rahul's salary
Increase the salary of the employee named Rahul to ₹75,000.
DELETE Statement
UseDELETE FROM to remove rows that match a condition.
Practice: Delete employee Sneha
Practice: Delete employee Sneha
Summary
In this chapter you learned:- Why SQLite is a great choice for learning and development
- The four SQL command categories: DDL, DML, DQL, and TCL
- SQLite’s five data types:
INTEGER,REAL,TEXT,BLOB,NULL CREATE TABLE— define new tables with constraintsALTER TABLE— add or rename columnsDROP TABLE— permanently delete a tableINSERT— add single or multiple rowsUPDATE— modify existing rows (always useWHERE!)DELETE— remove rows (always useWHERE!)