Database Structure: Server → Table
How objects are nested — server, database, schema, table — and how tables are physically stored on disk.
A big company does not keep all its data in one giant table. Data is arranged in a hierarchy, like a library: the building (server) has many sections (databases), each section has shelves (schemas), and each shelf holds books (tables). Knowing this hierarchy helps you read error messages, write full object names, and talk confidently with database admins.
Definition
Database hierarchy: a server holds many databases; a database groups related schemas; a schema is a named container (namespace) that groups related tables and other objects; a table holds the actual rows of data.
text
SERVER
├── DATABASE: IPL_Stats
│ ├── schema: matches → tables: innings, balls
│ └── schema: players → tables: players, teams
└── DATABASE: IPL_Fans
├── schema: tickets → tables: orders, seats
└── schema: app → tables: users, sessionsEach level explained
| Level | Definition | IPL example |
|---|---|---|
| Server | The machine/instance running the DBMS | IPL-SQL-01 |
| Database | A self-contained collection of related data, with its own files, users and backups | IPL_Stats, IPL_Fans |
| Schema | A logical folder inside a database that groups objects and controls permissions | matches, players, tickets |
| Table | Rows and columns that hold the actual data | innings, players |
Why schemas? They keep things organised and secure. The ticketing team can be given permission on the tickets schema only, without touching the app schema. Two schemas can even contain tables with the same name (tickets.orders and app.orders) without a clash.
Note: In SQL Server every database has a default schema called
dbo(database owner). If you create a table without naming a schema, it goes intodbo.
Fully qualified names
Because of the hierarchy, a table can be referred to by a longer, unambiguous name:
sql
-- table only (uses your current database and default schema)
SELECT * FROM players;
-- schema.table
SELECT * FROM dbo.players;
-- database.schema.table
SELECT * FROM IPL_Stats.dbo.players;The pattern is server.database.schema.table (the server part is only used for linked servers). Most of the time you write just the table name, after choosing the database with USE IPL_Stats;.
How tables are stored on disk
The table you see in a query result is a logical view. Physically, SQL Server saves everything in database files on the disk:
| File | Extension | What it holds |
|---|---|---|
| Primary data file | .mdf | The tables, rows and indexes |
| Secondary data file | .ndf (optional) | Extra data files for large databases |
| Transaction log file | .ldf | A record of every change, used for recovery |
Inside a data file the rows are saved in small blocks called pages (8 KB each in SQL Server). When you run a query, the DBMS reads the needed pages from disk into memory and shows you a neat table. You never open the .mdf file yourself — the DBMS does that for you.
Note: Strictly speaking the files belong to the database, not to one table — one
IPL_Stats.mdffile holds all tables of that database.
A single value at one row-and-column position — for example 'Virat Kohli' in the name column of row 1 — is called a cell (or field value).
Common mistakes
- ❌ Treating "schema" as a synonym for "database". ✅ In SQL Server a schema lives inside a database. (In MySQL, though, the words schema and database mean the same thing.)
- ❌ Getting "Invalid object name 'players'" and assuming the table is missing. ✅ Check you are in the right database (
USE IPL_Stats;) and the right schema (matches.inningsvsdbo.innings).
SQL Server vs MySQL / PostgreSQL
| SQL Server | MySQL | PostgreSQL | |
|---|---|---|---|
| Schema inside a database? | Yes (default dbo) | Schema = database | Yes (default public) |
| Typical full name | IPL_Stats.dbo.players | IPL_Stats.players | public.players |
Interview tip
Q: What is a schema in SQL Server and why use one?
A: A schema is a named container inside a database that groups tables, views and other objects. It helps organise objects by area (sales, HR, tickets), lets you grant permissions at schema level, and allows the same object name in different schemas. The default schema is dbo.
Key points to remember
- Hierarchy: a server holds databases → a database groups schemas → a schema groups tables → a table holds rows.
- A schema is a named container (namespace) inside a database used to organise objects and manage permissions.
- SQL Server's default schema is dbo; a full name looks like IPL_Stats.dbo.players.
- SQL Server stores a database in files: .mdf (data), optional .ndf (extra data) and .ldf (transaction log).
- Rows are physically saved in 8 KB pages inside the data files; the DBMS turns them into the tables you see.
- A cell is one value at one row-and-column position.
- In MySQL 'schema' and 'database' mean the same thing; in SQL Server and PostgreSQL a schema lives inside a database.
Try it yourself
Full three-part names (SQL Server)
-- Choose the database first
USE IPL_Stats;
-- Same table, three ways of naming it
SELECT * FROM players;
SELECT * FROM dbo.players;
SELECT * FROM IPL_Stats.dbo.players;
-- Create a schema and a table inside it
CREATE SCHEMA tickets;
CREATE TABLE tickets.orders (
order_id INT PRIMARY KEY,
fan_name VARCHAR(50),
amount DECIMAL(8, 2)
);SQL Server-specific — run this in SQL Server (SSMS / Azure Data Studio).
Try it: the playground's single database
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Practice: find one cell
Runs on a fresh IPL practice database in your browser · edit the query and press Ctrl + Enter
Revision Flashcards
Tap a card to flip it and see the answer.
