Relational Model: Tables, Rows, Columns & Schemas
Map entities to tables, attributes to columns, and organize objects under schemas.
In plain words
Data lives in tables. Columns say what kind of information it is, rows are the individual things, and tables connect using IDs.
Think of it like…
A well-run spreadsheet workbook with strict rules: each sheet holds one kind of thing, each column has one meaning and type, each row is one item with a unique ID, and sheets refer to each other by those IDs instead of copying data.
Where you’ve seen it
A shop's database: customers(id, name, city), orders(id, customer_id, amount, created_at), products(id, name, price). An order doesn't contain a copy of the customer, just customer_id, and a join brings them together when needed.
Words you’ll hear
- Relation / table
- A set of rows with the same columns.
- Attribute / column
- A named property with a data type (domain).
- Tuple / row
- One record: one value per column.
- Schema
- The structure of the data; in PostgreSQL also a namespace (database → schema → table).
Visual diagram
Theory & example queries
The building blocks
Edgar F. Codd proposed the relational model in 1970. A relation is a set of tuples, so in theory rows have no order and no duplicates. SQL tables relax that a little (they can hold duplicate rows), but the lack of order is real: without ORDER BY, the database may return rows in any order, and that order can change between runs.
Each column has a type that restricts its values, and constraints add more rules. A primary key identifies each row; foreign keys store the key of a related row. Relationships live in the data itself, as matching values, which is what lets you join tables in ways nobody planned when the schema was designed.
| id | name | city | |
|---|---|---|---|
| 1 | Maya | maya@example.com | Pune |
| 2 | Ravi | ravi@example.com | Delhi |
| 3 | Noor | noor@example.com | Mumbai |
SELECT city, COUNT(*) AS customersFROM customersGROUP BY cityPostgreSQL is the lesson baseline unless noted otherwise.
Calculate the selected expressions and return the requested output columns.
Representative grouped result3 sample rows
| city | customers |
|---|---|
| Bengaluru | 42 |
| Mumbai | 35 |
| Pune | 18 |
Note: Counts are illustrative for the customers table. GROUP BY has no guaranteed result order without an ORDER BY clause.
returns a table with two columns, which can itself be used in FROM, joined or filtered.
Key takeaway: Tables of typed columns, rows identified by keys, linked by values.
Schemas and organisation
"Schema" has two meanings. Generally, it's the design: the tables, columns, types and constraints. In PostgreSQL it's also a namespace inside a database (app.orders, analytics.orders), with public as the default and search_path controlling which schemas unqualified names refer to. In MySQL, "schema" and "database" mean the same thing.
Organising tables into schemas by area (app, billing, analytics) keeps large databases readable and makes permissions simpler, since you can grant access to a whole schema.
| day | amount |
|---|---|
| 2026-11-15 | 100 |
| 2026-11-17 | 200 |
| 2026-11-21 | 50 |
| 2026-11-22 | 75 |
CREATE SCHEMA analytics;CREATE TABLE analytics.daily_revenue (DAY date PRIMARY KEY, revenue numeric);PostgreSQL is the lesson baseline unless noted otherwise.
Identify the table or database object the statement will modify.
SELECT *FROM analytics.daily_revenue;PostgreSQL is the lesson baseline unless noted otherwise.
Calculate the selected expressions and return the requested output columns.
Representative analytics query result2 sample rows
| day | revenue |
|---|---|
| 2026-11-20 | 125000 |
| 2026-11-21 | 142500 |
Note: The sample assumes the analytics schema and table were created successfully and then populated. PostgreSQL reports CREATE SCHEMA and CREATE TABLE before the SELECT rows are returned.
then
Key takeaway: In PostgreSQL: database → schema → table.
How it works, step by step
Follow one practical SQL workflow from start to finish. Select any step or play through the flow.
Identify the things
List the entities the system tracks (customers, orders, products). Each usually becomes a table.
customers · orders · products
When to use it & trade-offs
What it is
The relational model stores data as tables (relations). Each column (attribute) has a name and a type, each row (tuple) is one fact, and every table has a key that identifies its rows. Tables are linked by key values rather than pointers, and every query takes tables in and returns a table out. A schema describes this structure, and in PostgreSQL it's also a named folder of tables.
Why it matters: Every SQL concept, from joins and keys to normalisation, builds on this model. Knowing its rules explains behaviour that surprises beginners, such as rows having no built-in order, and why results always come back as a table you can query again.
When to reach for it
- Designing any transactional application's data
- Explaining what tables, rows, columns and keys are
- Understanding why SQL results need ORDER BY
When to avoid or be careful
- Copying related data into every table instead of linking by key
- Relying on rows coming back in insert order
- Mixing several kinds of things in one table
Relational tables vs spreadsheets vs documents
Strengths: Types, keys, constraints, joins and transactions.
Watch out: Needs a designed schema up front.
Strengths: Easy to start and edit by hand.
Watch out: No enforced types or keys; copies drift apart.
Strengths: Flexible structure.
Watch out: Relationships and integrity are up to the application.
Interview signals & numbers to know
When this topic comes up
- “What is a relational database?”
- “Explain tables, rows and columns”
- “What is a schema?”
- Fresher interviews
- “Why did my rows come back in a different order?”
Benchmarks & rules of thumb
- 1970
- Codd's relational model paper
- 0
- guaranteed row order without ORDER BY
- 1
- primary key per table
Common mistakes & follow-ups
Common interview mistakes
- Assuming SELECT without ORDER BY returns rows in the order they were inserted.
- Storing a customer's name and city on every order instead of a customer_id.
- Confusing a PostgreSQL schema (a namespace) with the general meaning of schema (the design).
Likely interviewer follow-ups
- What's the difference between a table, a relation and a schema?
- Why don't SQL tables have a guaranteed row order?
- How are relationships represented in a relational database?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Relational Model: Tables, Rows, Columns & Schemas with hands-on SQL practice and interview Q&A.