Database Spreadsheets or Databases
What you will learn
- What a spreadsheet does well
- Where spreadsheets start to hurt
- What a database adds: rules, links between tables and safe sharing
- A simple test for choosing between the two
1. What spreadsheets do well
A spreadsheet is a grid of cells. It is quick to start, easy to see, and good for calculations, charts and one-off lists. For a single person with a small list, it is often the right tool. Nothing in this course says "never use a spreadsheet".
2. Where spreadsheets start to hurt
| Problem | What happens |
|---|---|
| No rules | any cell accepts anything: 25, twenty-two, or nothing |
| Repeated data | the same customer is typed again on every order row, and the copies drift apart |
| Everything in one grid | customers, orders and products are mixed in one sheet, or spread over sheets that are joined by hand |
| Sharing | two people editing copies leads to conflicting versions |
| Size | very large lists become slow and hard to search |
Here is the first problem in action. Imagine a column of numbers typed into a sheet. A sheet keeps every cell as typed, including words in a number column. Now we put the same four rows into a database table that has rules. The lesson's SQL runs on the sample database you choose with the Example data picker at the top, in your browser; the new table is created in your own copy of it.
A stock list with a rule: the quantity must be a number from 0 to 10000. Row 1 is fine:
CREATE TABLE stock_counts (
id INTEGER PRIMARY KEY,
item TEXT NOT NULL,
quantity INTEGER CHECK (quantity BETWEEN 0 AND 10000)
);
INSERT INTO stock_counts (item, quantity) VALUES ('Mug', 25);
(1 row changed)
Row 2 has a word where a number belongs:
INSERT INTO stock_counts (item, quantity) VALUES ('Lamp', 'twenty-two');
IntegrityError: CHECK constraint failed: quantity BETWEEN 0 AND 10000
Rows 3 and 4: an unknown quantity, and the first row typed again:
INSERT INTO stock_counts (item, quantity) VALUES ('Pen', NULL);
INSERT INTO stock_counts (item, quantity) VALUES ('Mug', 25);
SELECT id, item, quantity FROM stock_counts ORDER BY id;
id item quantity
-- ---- --------
1 Mug 25
2 Pen NULL
3 Mug 25
(3 rows)
A list of standing orders with a rule: the amount must be a number of cents from 0 to 1000000. Row 1 is fine:
CREATE TABLE standing_orders (
id INTEGER PRIMARY KEY,
payee TEXT NOT NULL,
amount_cents INTEGER CHECK (amount_cents BETWEEN 0 AND 1000000)
);
INSERT INTO standing_orders (payee, amount_cents) VALUES ('Rent', 120000);
(1 row changed)
Row 2 has words where a number belongs:
INSERT INTO standing_orders (payee, amount_cents) VALUES ('Gym', 'forty euros');
IntegrityError: CHECK constraint failed: amount_cents BETWEEN 0 AND 1000000
Rows 3 and 4: an unknown amount, and the first row typed again:
INSERT INTO standing_orders (payee, amount_cents) VALUES ('Phone', NULL);
INSERT INTO standing_orders (payee, amount_cents) VALUES ('Rent', 120000);
SELECT id, payee, amount_cents FROM standing_orders ORDER BY id;
id payee amount_cents
-- ----- ------------
1 Rent 120000
2 Phone NULL
3 Rent 120000
(3 rows)
A list of exam marks with a rule: the mark must be a number from 0 to 100. Row 1 is fine:
CREATE TABLE exam_marks (
id INTEGER PRIMARY KEY,
student TEXT NOT NULL,
mark INTEGER CHECK (mark BETWEEN 0 AND 100)
);
INSERT INTO exam_marks (student, mark) VALUES ('Rina', 85);
(1 row changed)
Row 2 has a word where a number belongs:
INSERT INTO exam_marks (student, mark) VALUES ('Sam', 'eighty');
IntegrityError: CHECK constraint failed: mark BETWEEN 0 AND 100
Rows 3 and 4: an unknown mark, and the first row typed again:
INSERT INTO exam_marks (student, mark) VALUES ('Lee', NULL);
INSERT INTO exam_marks (student, mark) VALUES ('Rina', 85);
SELECT id, student, mark FROM exam_marks ORDER BY id;
id student mark
-- ------- ----
1 Rina 85
2 Lee NULL
3 Rina 85
(3 rows)
- A spreadsheet would have kept all four rows, including the word in the number column.
- The table refused it (the
CHECKrule). It stored the empty value asNULL, meaning "unknown" (lesson 2.3). - The first row appears twice with nothing to say they are the same record. Giving each record a unique key (chapter 2) prevents that kind of confusion.
3. What a database adds: linked tables
The biggest change is that data is split into several tables that point to each other, instead of one wide grid. The sample database already has such tables:
Each order stores only the customer's id, not their name and details again. The JOIN puts the pieces back together when you ask:
SELECT c.last_name, o.order_id, o.order_date
FROM customers c
JOIN orders o ON o.customer_id = c.customer_id
WHERE c.customer_id = 279
ORDER BY o.order_id
LIMIT 4;
last_name order_id order_date
--------- -------- ----------
Wang 1 2025-04-23
Wang 194 2025-05-09
Wang 1111 2025-08-21
Wang 1358 2025-04-23
(4 rows)
If this customer's name changes, you fix it in one place, and every order shows the new name:
UPDATE customers SET last_name = 'Haque' WHERE customer_id = 279;
SELECT c.last_name, o.order_id, o.order_date
FROM customers c
JOIN orders o ON o.customer_id = c.customer_id
WHERE c.customer_id = 279
ORDER BY o.order_id
LIMIT 4;
last_name order_id order_date
--------- -------- ----------
Haque 1 2025-04-23
Haque 194 2025-05-09
Haque 1111 2025-08-21
Haque 1358 2025-04-23
(4 rows)
Each account stores only the customer's id, not their name and details again. The JOIN puts the pieces back together when you ask:
SELECT c.full_name, a.account_id, a.account_type
FROM customers c
JOIN accounts a ON a.customer_id = c.customer_id
WHERE c.customer_id = 77
ORDER BY a.account_id;
full_name account_id account_type
--------- ---------- ------------
Leo Kumar 1 checking
Leo Kumar 425 checking
(2 rows)
If this customer's name changes, you fix it in one place, and every account shows the new name:
UPDATE customers SET full_name = 'Leo Haque' WHERE customer_id = 77;
SELECT c.full_name, a.account_id, a.account_type
FROM customers c
JOIN accounts a ON a.customer_id = c.customer_id
WHERE c.customer_id = 77
ORDER BY a.account_id;
full_name account_id account_type
--------- ---------- ------------
Leo Haque 1 checking
Leo Haque 425 checking
(2 rows)
Each section stores only the course's id, not its code and title again. The JOIN puts the pieces back together when you ask:
SELECT c.title, s.section_id, s.term
FROM courses c
JOIN sections s ON s.course_id = c.course_id
WHERE c.course_id = 2
ORDER BY s.section_id;
title section_id term
-------- ---------- -----------
Geometry 2 2025-Spring
Geometry 3 2025-Autumn
Geometry 4 2026-Spring
(3 rows)
If the course title changes, you fix it in one place, and every section shows the new title:
UPDATE courses SET title = 'Plane Geometry' WHERE course_id = 2;
SELECT c.title, s.section_id, s.term
FROM courses c
JOIN sections s ON s.course_id = c.course_id
WHERE c.course_id = 2
ORDER BY s.section_id;
title section_id term
-------------- ---------- -----------
Plane Geometry 2 2025-Spring
Plane Geometry 3 2025-Autumn
Plane Geometry 4 2026-Spring
(3 rows)
This is the heart of the relational idea (chapters 2, 3 and 5). In a single wide sheet the name would be typed on every row, and you would have to fix every copy.
4. A simple test
| Question | Spreadsheet is fine | Prefer a database |
|---|---|---|
| People editing at the same time | one | several |
| Same fact repeated in many rows | rarely | often |
| Must bad data be refused | no | yes |
| Different kinds of things linked together | no | yes |
| Program needs to read and write the data | rarely | yes |
| Size | hundreds of rows | thousands or more |
Worked example: a class attendance list
A teacher keeps a list of 30 students with a tick for each day.
- One editor, small size, no links: a spreadsheet is fine.
Now the school wants every teacher to record attendance from their own phones, link students to classes and parents, and refuse a student that does not exist.
- Many editors, several linked kinds of things, rules needed: a database.
The school and names here are made up. The tool should follow the need, not the other way round.
Common mistakes
- Saying spreadsheets are bad. They are excellent for small, personal, calculation-heavy work.
- Copying the same customer details onto every order row. Store them once and link to them.
- Keeping a spreadsheet "just as a database" until it breaks. Move before the first serious data mistake, not after.
- Expecting a database to be as easy to eyeball. A database has no grid to scroll; you ask questions instead.
Key takeaways
- Spreadsheets suit small, personal lists and calculations.
- Databases add rules, linked tables, safe sharing and size.
- Splitting data into linked tables avoids repeating facts.
- Choose by need: editors, repeated data, rules, links and size.
Practice
1. Name two things a spreadsheet cell cannot refuse by itself.
Show answer
For example text in a number column, and a missing required value (unless extra checking is added).
2. In the lesson, why did the database refuse the word typed into the number column?
Show answer
The CHECK (... BETWEEN ... AND ...) rule is not satisfied by text that is not a number in that range.
3. Why does an order, an account or a section row store an id of another row instead of that row's name?
Show answer
So each fact is stored once; a change is made in one place and the join combines the pieces when needed.
4. What does JOIN do?
Show answer
It combines rows from two tables where a condition matches, for example where orders.customer_id equals customers.customer_id.
5. A single person keeps a monthly budget with a few formulas. Spreadsheet or database?
Show answer
A spreadsheet: one editor, small size, calculations, no linked kinds of data.
6. Give one sign that a spreadsheet has outgrown its job.
Show answer
For example the same fact repeated in many rows and getting out of step, several people overwriting each other's copies, or bad entries that nobody catches.