Skip to main content
Before you can query data, you need somewhere to store it. This page introduces SQLite — the lightweight, serverless database engine you’ll use throughout this course — and then covers the two families of SQL commands that let you build and populate that database: Data Definition Language (DDL) for shaping the structure of your tables, and Data Manipulation Language (DML) for adding, changing, and removing the rows inside them.

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 .db file works on Windows, macOS, and Linux
  • ACID-compliant — your data is safe even if the app crashes
  • Fully supports standard SQL syntax
Limitations to keep in mind:
  • Not designed for high-concurrency production workloads
  • Limited support for ALTER TABLE compared 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:
Choose the appropriate SQLite data type for each attribute:

DDL: Defining Your Schema

CREATE TABLE

Use CREATE TABLE to define a new table and its columns. You specify each column’s name, data type, and any constraints.
Key constraints explained:
Write a CREATE TABLE statement for a student table with student_id, student_name, and email.

ALTER TABLE

Use ALTER TABLE to modify an existing table without dropping and recreating it. Add a new column:
Rename an existing column:
SQLite has limited ALTER TABLE support compared to other databases. You cannot drop columns or change data types directly in older SQLite versions. In SQLite 3.35+ you can use DROP 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.
DROP TABLE is irreversible. All rows in the table are permanently deleted. Always back up your data or use a test database when experimenting with destructive commands.

DML: Manipulating Your Data

INSERT Statement

Use INSERT INTO to add new rows to a table. Insert a single row (all columns, in order):
Insert multiple rows at once:
Insert by explicitly naming columns (recommended practice):
Always list column names explicitly in your INSERT statements. This makes your code resilient to future schema changes and easier to read.
Insert an employee named Anitha with employee_id 102 and a salary of ₹55,000 in Bengaluru, assigned to department 2.

UPDATE Statement

Use UPDATE to modify existing rows.
You can update multiple columns in one statement:
Always include a WHERE clause with UPDATE unless you genuinely intend to update every row in the table. Running UPDATE employee SET salary = 0; without a filter will zero out every employee’s salary.
Increase the salary of the employee named Rahul to ₹75,000.

DELETE Statement

Use DELETE FROM to remove rows that match a condition.
Omitting the WHERE clause deletes all rows from the table while leaving the table structure intact. This is different from DROP TABLE, which removes the table itself.

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 constraints
  • ALTER TABLE — add or rename columns
  • DROP TABLE — permanently delete a table
  • INSERT — add single or multiple rows
  • UPDATE — modify existing rows (always use WHERE!)
  • DELETE — remove rows (always use WHERE!)
The next chapter focuses entirely on DQL (SELECT) — retrieving, filtering, sorting, grouping, and analyzing the data you’ve stored.