What a database, a table and SQL are
A relational database stores data in tables of rows and columns, and SQL (Structured Query Language) is the language you use to ask it questions and to change what it holds.
Why it matters
A spreadsheet works for a few hundred rows and one person. An app with thousands of users needs data that many people can read and change at the same time, safely, without losing anything, and fast enough to answer in milliseconds. A database does that job, and SQL is how you talk to it.
The idea
A database is an organised store of data, run by a program called a DBMS (database management system), such as PostgreSQL, MySQL, SQL Server or SQLite.
The data lives in tables. A table is like one sheet in a spreadsheet: each row is one thing (one employee, one order) and each column is one fact about it (name, salary).
You never open the files yourself. You send the database a query — a request written in SQL — and it sends back rows.
A library with a librarian. The shelves are the tables, each book is a row, and the details on its catalogue card (title, author, year) are the columns. You don't walk the shelves yourself: you hand the librarian a request slip — "every book by this author, newest first" — and they bring back exactly those books.
A librarian fetches books one by one, in the order you asked. SQL is declarative: you describe what you want, not how to get it, and the database picks its own way. That is why the order you write a query in is not the order it runs in.
Syntax
SELECT column, other_column
FROM table_name
WHERE condition;How it works
- You write a query in SQL, for example: give me the name and salary of everyone in department 1.
- You send it to the database, from a SQL editor, a Python script, or your app's backend.
- The database checks the query makes sense: do these tables and columns exist?
- Its query planner picks the fastest way to find the rows, for example by using an index.
- It runs that plan and returns the result: a new, temporary table of rows and columns.
- Reading never changes the stored tables. A SELECT is always safe to run.
Key points
- A table holds one kind of thing. A row is one of them; a column is one fact about each.
- SQL is declarative: you say what you want, and the database decides how to get it.
- The result of a query is itself a table. That is why a query can be put inside another query.
- SQL keywords are not case-sensitive (
selectworks), but writing them in capitals makes a query easier to read. - Every major database speaks SQL. The core is the same everywhere; small details such as dates and LIMIT differ, and these notes point them out.
- How databases scale — SQL versus NoSQL, replication, sharding — is in System Design, Unit 3: Data.
Common mistakes
- Thinking SQL runs top to bottom like Python. It doesn't: the database reads FROM first and SELECT near the end.
- Thinking a database is just a big spreadsheet. It also enforces rules, handles many users at once and survives crashes.
- Forgetting the semicolon between two statements. One statement on its own usually runs without it.
Not true: A database is a big spreadsheet: it stores rows, and that is its whole job.
In fact: A database also enforces rules on the data, serves many users at the same time and survives crashes. A spreadsheet does none of these.
In the interview
A relational database stores data in tables, where each row is one record and each column is one attribute, and the tables are linked through keys. SQL is the declarative language for querying and changing that data: I describe the result I want, and the database's optimiser decides how to get it. That separation is why the same query can become much faster just by adding an index.
Part of Unit 0: Start here: databases, tables and SQL in the free SQL course.