Database Management Systems
What you will learn
- What a DBMS is and how it differs from a database
- The jobs a DBMS does for you
- How to see a DBMS work using SQLite
- That popular DBMSs have different strengths
1. Database and DBMS
A database is the organised data. A database management system (DBMS) is the software that stores it, answers questions, enforces rules and lets many users share it safely. People often say "database" for both, but the difference helps:
| Term | Example |
|---|---|
| Database (the data) | the shop.db file, with its items and orders |
| DBMS (the software) | SQLite, PostgreSQL, MySQL, MongoDB |
You never edit the stored bytes yourself. You send a request to the DBMS and it does the work.
2. The jobs of a DBMS
| Job | Meaning |
|---|---|
| Store | write data to disk in an efficient layout |
| Find | answer questions quickly (planning the search; lesson 7.6) |
| Check | enforce rules such as NOT NULL and keys (chapter 2) |
| Share | let many users work at once without damaging each other (chapter 6) |
| Protect | permissions and backups (chapter 8) |
A DBMS is usually built from a few cooperating parts. The names and splits differ from product to product, but this picture is common (it is a general description, not the design of one system):
| Part | What it does |
|---|---|
| Query processor | reads the SQL, checks it, and chooses a plan (an order of steps) to answer it |
| Storage engine | keeps tables and indexes in files, in pages that are read into memory as needed |
| Transaction and lock manager | makes changes all-or-nothing and keeps simultaneous users apart (chapter 6) |
| Logs and recovery | record changes so the data can be repaired after a crash (chapters 6 and 8) |
| Security and administration | users, permissions, settings and monitoring (chapters 8 and 12) |
Programs talk to the top of this stack by sending queries and never touch the files underneath. That separation is why a database can change how it stores data without breaking your program.
3. Watching one work
SQLite is a DBMS that keeps a whole database in one ordinary file. Let us create a file, store a row, close everything, and read it back.
import sqlite3, os, tempfile
path = os.path.join(tempfile.mkdtemp(), "shop.db")
con = sqlite3.connect(path)
con.execute("CREATE TABLE items (id INTEGER PRIMARY KEY, name TEXT, price REAL)")
con.execute("INSERT INTO items (name, price) VALUES ('shirt', 450.0)")
con.commit(); con.close()
print("file exists:", os.path.exists(path), "| bytes > 0:", os.path.getsize(path) > 0)
con = sqlite3.connect(path)
print(con.execute("SELECT name, price FROM items").fetchall())
for row in con.execute("EXPLAIN QUERY PLAN SELECT * FROM items WHERE id = 1"):
print(row[3])
con.close()
file exists: True | bytes > 0: True
[('shirt', 450.0)]
SEARCH items USING INTEGER PRIMARY KEY (rowid=?)
- The data survived closing the connection: it lives in the file.
EXPLAIN QUERY PLANasks the DBMS how it intends to answer. It chose to look up the row directly by its key instead of reading every row. You did not tell it to; that is the DBMS working out the how (lesson 7.6).
A second connection to the same file sees data that the first one has committed:
a = sqlite3.connect(path); b = sqlite3.connect(path)
a.execute("INSERT INTO items (name, price) VALUES ('scarf', 120.0)"); a.commit()
print(b.execute("SELECT COUNT(*) FROM items").fetchone())
(2,)
That is the "share" job: two users, one set of data, and b sees the committed row.
4. Different DBMSs
Many DBMSs exist. They all store and protect data, but they are built for different settings. SQLite runs inside your program and needs no separate server; PostgreSQL, MySQL and MongoDB run as servers that programs connect to (lesson 1.5). Lesson 1.4 explains the main kinds, and chapter 9 how to choose.
Worked example: who does what?
A shop app wants to show "orders from the last week".
- The app sends a request to the DBMS (a SQL sentence).
- The DBMS plans the search, finds the rows and checks nothing is mid-change.
- The DBMS returns the rows.
- The app shows them.
The app never opened the data file or looked for the rows itself. Names and shop are made up.
The "request" in step 1 is just a SQL sentence. The sample databases are real SQLite files (shop.db, bank.db, school.db) managed by a DBMS in your browser. Use the Example data picker at the top, and press Run to send a request yourself:
Orders from the last week of the data:
SELECT order_id, order_date, status FROM orders WHERE order_date >= '2026-09-24' ORDER BY order_date, order_id LIMIT 5;
order_id order_date status
-------- ---------- ---------
269 2026-09-24 pending
2373 2026-09-24 shipped
338 2026-09-25 pending
475 2026-09-25 pending
522 2026-09-25 delivered
(5 rows)
Ledger entries from the last week of the data:
SELECT txn_id, txn_date, kind FROM transactions WHERE txn_date >= '2026-09-24' ORDER BY txn_date, txn_id LIMIT 5;
txn_id txn_date kind
------ ---------- ----------
7377 2026-09-24 withdrawal
7378 2026-09-24 deposit
7379 2026-09-24 withdrawal
7380 2026-09-24 withdrawal
7381 2026-09-24 interest
(5 rows)
Assignments due in the last weeks of the data:
SELECT assignment_id, title, due_date FROM assignments WHERE due_date >= '2026-04-20' ORDER BY due_date, assignment_id LIMIT 5;
assignment_id title due_date
------------- ---------- ----------
118 Homework 2 2026-04-20
93 Project 2026-04-23
160 Lab report 2026-04-23
104 Quiz 1 2026-04-24
123 Lab report 2026-04-24
(5 rows)
You wrote only what you want. The DBMS planned the search, found the rows and returned them.
Common mistakes
- Using "database" and "DBMS" as exact synonyms in a way that confuses people. When it matters, say which you mean.
- Opening and editing the data file by hand. Always go through the DBMS.
- Forgetting
commit(). Changes not committed may be lost (chapter 6). - Assuming all DBMSs behave the same. They share ideas but differ in details.
Key takeaways
- The database is the data; the DBMS is the software that manages it.
- A DBMS stores, finds, checks, shares and protects.
- SQLite keeps a database in one file and is easy to try.
- You state what you want; the DBMS decides how.
Practice
1. What is the difference between a database and a DBMS?
Show answer
The database is the organised data; the DBMS is the software that manages it.
2. Name the five jobs of a DBMS.
Show answer
Store, find, check, share and protect.
3. What did EXPLAIN QUERY PLAN show in the lesson?
Show answer
How SQLite planned to answer the query: a direct search by the row's primary key rather than reading every row.
4. Why must you call commit() before another connection can see your insert?
Show answer
Until the change is committed it is not yet a permanent, shared part of the database (chapter 6 explains this fully).
5. Which of these is a DBMS: shop.db, SQLite?
Show answer
SQLite is the DBMS; shop.db is a database file it manages.
6. Why should you not edit a database file with a text editor?
Show answer
It is in a format the DBMS manages; editing it directly can corrupt it and bypasses the rules and safety checks.