Schema vs Table vs Database: What Is the Difference?
A database holds schemas, a schema holds tables, and a table holds rows. The three are containers nested inside each other, not competing ideas.
A table stores data. A schema is a named folder that groups tables and other objects.
The three levels
| Level | What it is | What it contains | Example name |
|---|---|---|---|
| Database | The whole storage unit, with its own users and settings. | Schemas | shop |
| Schema | A named group inside a database. | Tables, views, indexes, functions | sales |
| Table | A grid of rows and columns. | Rows of data | orders |
The full name of an object reads from the outside in. In PostgreSQL you write shop.sales.orders.
Most queries leave the first two parts out. The connection already names the database, and a search path fills in the schema.
What a table is
A table is a grid. Each column has a name and a data type. Each row is one record.
| order_id | customer_id | amount | status |
|---|---|---|---|
| 101 | 1 | 250.00 | shipped |
| 102 | 2 | 150.00 | pending |
A primary key marks the column that identifies each row, here order_id. A foreign key points at a row in another table, here customer_id.
Tables are the only objects in this list that store data. A schema stores nothing on its own.
Creating one inside the other
Three statements show the nesting clearly.
CREATE DATABASE shop; CREATE SCHEMA sales; CREATE TABLE sales.orders ( order_id INT PRIMARY KEY, customer_id INT NOT NULL, amount DECIMAL(10,2), status VARCHAR(20) );
Drop the schema and every table inside it goes too. Drop a table and the schema stays.
The word schema has three meanings
This is where the confusion starts. The same word is used for three different things.
| Meaning | What people mean | Where you hear it |
|---|---|---|
| A namespace | A named container for tables inside a database. | SQL code, permissions, CREATE SCHEMA |
| A table schema | The column names, types and constraints of one table. | DESCRIBE orders, migration files |
| A database schema | The whole design: every table, key and relationship. | Design reviews, ER diagrams |
The third meaning is a blueprint, not an object you can create. When a course says the schema is the design of the database, that is the meaning it uses.
The first meaning is the one your SQL client enforces. Both are correct in their own setting.
Each engine treats schemas differently
This difference causes real bugs when moving code between systems.
| Engine | How a schema behaves |
|---|---|
| PostgreSQL | A real namespace inside a database. Each database can hold many schemas. The default one is public. |
| SQL Server | Same as PostgreSQL. The default schema is dbo. |
| Oracle | A schema equals a user. Creating a user creates that user's schema. |
| MySQL | SCHEMA is another word for DATABASE. There is no level between them. |
| SQLite | No schemas at all. Attached database files serve a similar role. |
So in MySQL, schema and database mean the same thing. In PostgreSQL they do not. Read any comparison with the engine in mind.
Why teams use schemas
Splitting one database into schemas costs nothing and solves four problems.
- Name collisions. Two teams can each own a table called
events. - Permissions. You can grant read access to one schema instead of listing every table.
- Separation by area.
sales,billingandauditkeep related tables together. - Tenant isolation. Some products give each customer a schema inside one shared database.
The cost is that queries and migrations must be schema aware. A missing search path setting sends a query to the wrong table.
How to Prepare
- Say the nesting in one line. Database contains schema, schema contains table, table contains rows. That answers most versions of the question.
- Name your engine. Add that MySQL treats schema and database as the same thing. Interviewers notice the detail.
- Draw it once. What is the difference between an ERD and a schema covers how the design is written down.
- Know how queries reach the data. What is a database query explains the SQL and NoSQL difference next to this one.
- Learn what happens when one database is not enough. Sharding and partitioning is the next step past schemas.
- Practice full data designs. Grokking System Design Fundamentals and Grokking the System Design Interview both include database modelling questions.

GET YOUR FREE
Coding Questions Catalog

$123

$197

$72