Lesson 1: Introduction to Relational Databases
02 Jul 2026 1 min Swarnil Singhai
A relational database stores data in tables of rows and columns, related to each other by keys — the model behind Postgres, MySQL, and SQLite alike.
Real-time example
An e-commerce system has customers, orders, and products as separate tables, linked instead of duplicated everywhere.
CREATE TABLE customers (
id SERIAL PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100) UNIQUE
);
CREATE TABLE orders (
id SERIAL PRIMARY KEY,
customer_id INT REFERENCES customers(id),
amount NUMERIC(10,2),
created_at TIMESTAMP DEFAULT now()
);
What's happening
customer_id REFERENCES customers(id) is a foreign key — the database itself enforces that every order belongs to a real customer.
Model your real-world entities as tables first; the relationships between them (keys) come next.
Advertisement