Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 2/ 160
01. SQL Foundations & Relational Concepts

Relational Model: Tables, Rows, Columns & Schemas

Map entities to tables, attributes to columns, and organize objects under schemas.

BeginnerTables · Rows · Schemas3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

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

Loading interactive 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.

A result is a table you can query againQuery example
1Input dataStart from the source rows or state that the statement sees.
customers
3 rows
customers sample rows
idnameemailcity
1Mayamaya@example.comPune
2Raviravi@example.comDelhi
3Noornoor@example.comMumbai
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  city,3  COUNT(*) AS customers4FROM5  customers6GROUP BY7  city
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/7
3OutputInspect the representative rows, affected-row count, plan, or command status.
Representative grouped result3 sample rows
Representative grouped result
citycustomers
Bengaluru42
Mumbai35
Pune18

Note: Counts are illustrative for the customers table. GROUP BY has no guaranteed result order without an ORDER BY clause.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

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.

Two schemas in one PostgreSQL databaseQuery example
1Input dataStart from the source rows or state that the statement sees.
daily_revenue
4 rows
daily_revenue sample rows
dayamount
2026-11-15100
2026-11-17200
2026-11-2150
2026-11-2275
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1CREATE SCHEMA analytics;23CREATE TABLE analytics.daily_revenue (DAY date PRIMARY KEY, revenue numeric);
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Choose the target

Identify the table or database object the statement will modify.

1/3
query.sql
1SELECT2  *3FROM4  analytics.daily_revenue;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/4
3OutputInspect the representative rows, affected-row count, plan, or command status.
Representative analytics query result2 sample rows
Representative analytics query result
dayrevenue
2026-11-20125000
2026-11-21142500

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.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

then

Key takeaway: In PostgreSQL: database → schema → table.

Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Design

Identify the things

List the entities the system tracks (customers, orders, products). Each usually becomes a table.

Focus at this step

customers · orders · products

What to watch at this step
One table
per kind of thing
Tip: use ← → to move between steps

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

Relational tables
Best for: Structured, related data with integrity rules

Strengths: Types, keys, constraints, joins and transactions.

Watch out: Needs a designed schema up front.

Spreadsheets
Best for: Small, ad-hoc data handled by people

Strengths: Easy to start and edit by hand.

Watch out: No enforced types or keys; copies drift apart.

Documents (JSON)
Best for: Self-contained records with varying shapes

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?
Interview tip: Define table, row, column and key with one small example (customers and orders), and add the "no guaranteed order" point. It shows you understand the model, not just the vocabulary.

Knowledge check

Loading quiz

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.

Open SQL Practice →SQL interview Q&A
Previous topic
What is a Database? (DBMS vs RDBMS)
Next topic
SQL Dialects Overview (PostgreSQL, MySQL, SQL Server, SQLite, Oracle)