Modules / Database / Relational Lab

What are Relational Databases?

Data split across tables and stitched back together by keys. Click a row to follow its relationships, then flatten everything into one table to see exactly what normalisation is protecting you from.

Relational Databases: Small Tables, Strong Links

Fifty years on, the relational model is still the default way to store business data. This is why.

Quick Context

A relational database stores data in tables of rows and columns, where every table describes one kind of thing — customers, orders, products — and tables are connected by shared key values rather than by nesting data inside each other.

Keys Are the Whole Trick

  • Primary key — a column whose value uniquely identifies a row. No duplicates, never NULL. It is the row's permanent name.
  • Foreign key — a column holding the primary key of a row in another table. This is the link, and the database enforces it: you cannot create an order for customer 99 if no such customer exists.

That enforcement is called referential integrity, and it is a guarantee the database makes on your behalf — not something your application code has to remember.

Why Split the Data at All?

Switch this lab to one flat table and look at the red cells. The customer's name and city now repeat on every order they ever placed. That redundancy causes three classic problems:

  • Update anomaly — changing a customer's name means finding and editing every copy. Miss one and your data now contradicts itself. Press the rename button in both models and compare the counts.
  • Insertion anomaly — you cannot record a new customer until they place an order, because there is nowhere to put them.
  • Deletion anomaly — deleting a customer's only order erases the customer entirely.

Normalisation is the process of splitting tables until each fact is stored exactly once. The cost is that answering a question often requires a JOIN — and that trade, correctness for a little query effort, is the central bargain of the relational model.

ACID: The Other Half of the Promise

Relational systems also guarantee that transactions are Atomic (all steps or none), Consistent (constraints always hold), Isolated (concurrent transactions do not corrupt each other) and Durable (committed data survives a crash). If you are moving money between accounts, this is not a nice-to-have.

Interactive Exploration Guide

  1. Click a customer row. Their orders light up in the orders table — that is the foreign key doing its job.
  2. Click an order. The single product it references is highlighted. One value, one link, no ambiguity.
  3. Switch to the flat table and watch the cell count rise while the number of tables drops to one. Every red cell is a duplicated fact.
  4. Run the rename in both models. Normalised: one cell changes. Flat: several — and every one is an opportunity to get it wrong.

Key Takeaway

Store each fact once, identify it with a primary key, and reference it with a foreign key. The database then enforces the relationships for you. Flattening everything looks simpler until the first time you have to change something.

Cheat sheet

What are Relational Databases?

Data split across tables and stitched back together by keys. Click a row to follow its relationships, then flatten everything into one table to see exactly what normalisation is protecting you from.

DATABASE · vizlearn.in/database/what_are_relational_databases.html