Skip to content

MySQL Tutorial Getting Started with MySQL

Relational Databases Explained

Lesson 5 of 308 2 min read By Deepak Paswan Updated Oct 5, 2026

MySQL is a relational database. The word “relational” comes from relations, a mathematical word for tables. The big idea is simple:

Store each kind of thing in its own table, and connect the tables with keys.

The problem with one big table

Imagine a shop that records orders in a single table:

order_idcustomer_namecustomer_cityproductprice
1Maya ShahPuneNotebook80
2Maya ShahPuneBackpack999
3Rohan VermaDelhiNotebook80

Maya’s name and city are written twice. If she moves, you must fix every row, and if you miss one, the data disagrees with itself. The price of a notebook is also repeated.

The relational solution

Split the data into separate tables, one per thing, and link them.

customers

idnamecity
1Maya ShahPune
2Rohan VermaDelhi

orders

idcustomer_idproductprice
11Notebook80
21Backpack999
32Notebook80

Maya now appears once. Her orders point to her with customer_id = 1.

Keys: the glue

  • A primary key is a column (here id) whose value is unique for every row. It identifies a row, like a roll number.
  • A foreign key is a column (here customer_id) that holds the primary key of a row in another table. It is the link.

You can follow the link in SQL with a JOIN. Here is a small preview. Do not worry about the details yet; the JOIN chapter explains every part.

query.sql
SQL
CREATE TABLE customers (
    id INT PRIMARY KEY,
    name VARCHAR(50),
    city VARCHAR(50)
);

CREATE TABLE orders (
    id INT PRIMARY KEY,
    customer_id INT,
    product VARCHAR(50),
    price INT
);

INSERT INTO customers VALUES (1, 'Maya Shah', 'Pune'), (2, 'Rohan Verma', 'Delhi');
INSERT INTO orders VALUES (1, 1, 'Notebook', 80), (2, 1, 'Backpack', 999), (3, 2, 'Notebook', 80);

SELECT customers.name, customers.city, orders.product
FROM orders
JOIN customers ON customers.id = orders.customer_id;
Output
OUTPUT
+-------------+-------+----------+
| name        | city  | product  |
+-------------+-------+----------+
| Maya Shah   | Pune  | Notebook |
| Maya Shah   | Pune  | Backpack |
| Rohan Verma | Delhi | Notebook |
+-------------+-------+----------+
3 rows in set

The query started from the orders and looked up each customer through the key. The customer’s data is stored once, and it is combined with the orders only when you ask.

What you gain

  • No repeated data. Change a city in one place.
  • Consistency. The database can refuse an order for a customer that does not exist (a foreign key rule).
  • Flexible questions. Because the data is in clean tables, you can combine it in ways you did not plan for.
lightbulb
Remember the shape
One table per kind of thing. One row per item. One column per fact. Keys to connect tables. Almost every database design follows this shape.