Why databases exist
Spreadsheets and files work — until several people and programs need the same data at the same time, correctly, forever. Learn what a database management system adds, and how the relational model organizes data into tables linked by keys.
In this lecture you will
- Explain the problems databases solve that files and spreadsheets don’t
- Describe tables, rows, columns, primary keys and foreign keys
- Explain how splitting data into related tables avoids duplication and contradictions
- Know where relational and non-relational databases fit
Almost every business starts its data life in spreadsheets. They are flexible, familiar and fine for one person. Then the company grows: ten people edit the same sheet, a program needs to read it every second, two versions disagree, someone overwrites a column, and nobody can say which number is right. That is the moment you need a database.
What a database system adds
A database management system (DBMS) — such as PostgreSQL, MySQL, SQL Server or Oracle — is software dedicated to storing data safely and answering questions about it. It adds guarantees that files and spreadsheets can’t offer:
- Concurrency
- Hundreds of users and programs can read and write at once without corrupting data or seeing half-finished changes.
- Integrity rules
- Constraints reject invalid data: a missing required field, a duplicate ID, an order for a customer who doesn’t exist.
- Durability
- Once a change is confirmed, it survives crashes and power cuts.
- Fast queries
- Indexes and a query planner find the right rows among millions in milliseconds.
- Security
- Fine-grained permissions control who can read or change what.
The relational model
The most widely used kind of database is relational. Data lives in tables: each table describes one kind of thing, each row is one instance, and each column is one attribute.
- A primary key uniquely identifies each row — usually an
idcolumn. - A foreign key is a column that holds another table’s primary key, linking the two.
The key idea is to store each fact once. A customer’s name and city live in one row of customers. Orders don’t repeat them; they just refer to the customer by customer_id. Explore the difference:
Splitting data this way — normalization — removes duplication, so updates happen in one place and the data can’t contradict itself. When you need the combined view, a join puts it back together at query time, which is the subject of lecture 3.
What goes wrong without it has names. Make each change below and compare the two designs:
Each problem comes from storing one fact in many places — or only as a side effect of another fact.
Describing a table
Tables are defined with SQL, the language of relational databases:
CREATE TABLE customers (
id BIGINT PRIMARY KEY,
name TEXT NOT NULL,
city TEXT NOT NULL,
created_at TIMESTAMP NOT NULL DEFAULT now()
);
CREATE TABLE orders (
id BIGINT PRIMARY KEY,
customer_id BIGINT NOT NULL REFERENCES customers(id),
product_id TEXT NOT NULL REFERENCES products(id),
qty INT NOT NULL CHECK (qty > 0)
);
The REFERENCES clause makes customer_id a foreign key: the database will refuse an order for a customer that doesn’t exist. NOT NULL and CHECK are further rules the database enforces for every program that touches the data — not just the one that remembered to validate.
You can try this right now. The playground below runs SQLite — a small but complete relational database — inside your browser, on tables with the same kinds of rules. Pick an example, press Run, then edit the statement and try to sneak bad data past it:
SQLite loads only when you press Run (about 0.7 MB). Everything runs on your device; Reset the data to start over.
Relational and NoSQL
Relational databases are the default choice for business data: orders, payments, users, inventory. Other models suit particular access patterns:
| Model | Examples | Good at |
|---|---|---|
| Relational | PostgreSQL, MySQL, SQL Server | Structured business data, flexible queries, strong consistency |
| Key-value | Redis, DynamoDB | Very fast lookups by key, caches, sessions |
| Document | MongoDB, Firestore | Nested, flexible records read as a whole |
| Wide-column | Cassandra, Bigtable | Huge write volumes, time series |
| Graph | Neo4j, Neptune | Highly connected data such as networks and recommendations |
Module 2 compares these in depth. This module focuses on the relational model and SQL — the foundation almost every data role relies on.
Next, we start asking the database questions — with SQL’s most important statement, SELECT.
Key takeaways
- A database management system provides safe concurrent access, consistency rules, durability and fast queries.
- Relational databases store data in tables; each row is identified by a primary key.
- Foreign keys link tables, so each fact is stored once and combined on demand with joins.
- Relational databases remain the default for business data; NoSQL systems serve specific access patterns.
Check your understanding
3 questions · answers explainedQ1In an orders table, what does a customer_id column that refers to customers.id represent?
Q2Why is storing a customer’s city in every one of their order rows a problem?
Q3Which is NOT something a database management system typically provides?