What is partitioning?
- SQL course
- Advanced
- Lesson 72/81
- 4 min
Split a large table into pieces.
What is a partition?
A partition splits a large table into pieces. Each piece is stored separately.
CREATE TABLE sales (id INT, sale_date DATE, amount DECIMAL)
PARTITION BY RANGE (sale_date);Partition by date.
The table sales is created.
What is a partition? — details
Partitioning improves query performance. Only relevant pieces are scanned.
For example, if you partition sales by year, a 2026 report reads only the 2026 partition; older years are never scanned.
Practice What is a partition?
Partition the sales table with PARTITION BY RANGE (sale_date).
Starter code
-- partition table
CREATE TABLE salesSample solution
CREATE TABLE sales (id INT, sale_date DATE, amount DECIMAL)
PARTITION BY RANGE (sale_date);Expected output
Tablo oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What does partitioning split?
- The view
- The index
- The table Correct answer
- The trigger
Explanation: Partitioning splits a table.
2 Add PARTITION BY
CREATE TABLE sales (id INT, sale_date DATE, amount DECIMAL)
____ RANGE (sale_date);
CREATE TABLE sales (id INT, sale_date DATE, amount DECIMAL)
PARTITION BY RANGE (sale_date);
Explanation: PARTITION BY is the right answer.
3 What is partitioning: match the terms
| Term | Meaning |
|---|---|
partition |
partition |
RANGE |
range |
LIST |
list |
HASH |
hash |