Learn SQL
-- fundamentals.why_database

Why use SQL / databases?

Spreadsheets break; databases scale

--concept

Storing data in files or spreadsheets works until many people read and write at once. Databases give you concurrent access with consistency rules, instant lookups over millions of rows via indexes, controlled permissions, and crash safety — while SQL remains the single, portable interface to all of it.

--how it works
1

Integrity is enforced by the engine

Column types, required fields and relationships are checked on every write — bad data is rejected at the door, not discovered in a report.

2

Indexes make scale boring

A query over 50 million rows answers in milliseconds because the engine walks an index (a sorted lookup structure), not the table itself.

3

Concurrency is safe by design

Hundreds of users read and write simultaneously; locking and MVCC ensure one person's half-finished change is invisible to the others.

4

Permissions are built in

GRANT and REVOKE control who reads or writes which tables and columns — no copy of the spreadsheet to leak.

5

Committed work survives crashes

The write-ahead log guarantees that once a transaction commits, it stays committed — even if the power fails a second later.

--visualization
📄 spreadsheet.csvone writer · whole-file locks · v17_final_FINAL✗ typos become facts✗ 10k rows = lag✗ overwrites collide✗ anyone can edit anything✗ corruption loses all🗄 databasethousands of users · rules enforced · safe✓ Integrity✓ Scale✓ Concurrency✓ Security✓ Durability
file pain database guarantee
Stage 1 / 7
“We keep everything in spreadsheets…” — fine for one person, fragile beyond that.
--example
query.sql
1SELECT COUNT(*) FROM employees; -- instant, even on 50 million rows
Result
COUNT(*)
6

The engine answers from metadata/index structures rather than reading every row one by one. Spreadsheets scan linearly and lock whole files; databases are built for exactly this question.

--variants

COUNT(*) at scale

Answering "how many rows?" from metadata instead of reading them.

query.sql
1SELECT COUNT(*) FROM employees;
Result
COUNT(*)
6
1On six rows the engine really does count them.
2On 50 million rows it usually answers from the smallest index or table metadata — no row-by-row walk.
3A spreadsheet asked the same question would scan every cell and lock the file while doing it.

Two writers, one row

Transactions keep simultaneous edits from trampling each other.

query.sql
1BEGIN;
2UPDATE employees SET salary = 56000 WHERE id = 2;
3-- second user reads salary: still 52000
4COMMIT;
Result
idnamedepartmentsalaryage
2BobSales5600035
1BEGIN opens a transaction: your change becomes visible to others only at COMMIT.
2Until then, other readers see the last committed value (52000) — no torn reads.
3COMMIT lands the change atomically; a crash before it would ROLLBACK automatically.

Least-privilege access

Each role sees exactly what it needs — enforced by the engine.

query.sql
1CREATE ROLE analyst;
2GRANT SELECT ON employees TO analyst;
3-- analyst can read but never:
4-- UPDATE / DELETE / INSERT on employees
1GRANT SELECT gives read-only power — the engine itself refuses anything else.
2This beats handing everyone the full spreadsheet "please don't edit" file.
3Roles can be granted per table or even per column.

Crash safety

Committed changes survive power loss via the write-ahead log.

query.sql
1BEGIN;
2UPDATE employees SET bonus = 5000 WHERE id = 1;
3COMMIT; -- power fails 1s later
4-- after restart: bonus is still 5000 ✓
Result
idnamedepartmentsalaryage
1AliceEngineering8500029
1At COMMIT the change is first flushed to a durable log on disk.
2The table itself may be updated lazily afterwards — the log is the source of truth.
3After a crash the engine replays the log: committed work survives, half-done work vanishes.
--key facts
Who uses itevery bank, hospital, airline, game backend and web app you use today
Career valueSQL appears in more developer/data job postings than any other single skill
Free toolsSQLite (zero setup) or PostgreSQL — practise everything on this page locally
--use cases
Any multi-user product: web shops, booking systems, social apps, games
Banking and payments, where a lost or duplicated write is real money
Reporting and analytics over data too large for spreadsheet tools
Replacing shared-drive "final_v17.xlsx" workflows inside teams
--under the hood
Databases price consistency, concurrency and durability — spreadsheets price familiarity; past a few simultaneous writers the trade flips.
SQLite is enough to feel every concept in this course; PostgreSQL demonstrates the same ideas at petabyte scale.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Take the queries you just visualized and see the data structures that power real databases.