A collection of database exercises for learning through practice โ covering both database design (ER modeling, normalization, relationships) and SQL (DDL, DML, DQL, joins, aggregation, subqueries, window functions, and more). Each exercise is documented with clear descriptions in both English and Arabic.
ู ุฌู ูุนุฉ ู ู ุชู ุงุฑูู ููุงุนุฏ ุงูุจูุงูุงุช ููุชุนูู ู ู ุฎูุงู ุงูู ู ุงุฑุณุฉ โ ุชุบุทู ุชุตู ูู ููุงุนุฏ ุงูุจูุงูุงุช (ูู ุฐุฌุฉ ERุ ุงูุชุทุจูุนุ ุงูุนูุงูุงุช) ู SQL (DDL, DML, DQLุ ุงูุฌูููุฒุ ุงูุชุฌู ูุนุ ุงูุงุณุชุนูุงู ุงุช ุงููุฑุนูุฉุ ุฏูุงู ุงููุงูุฐุฉุ ูุบูุฑูุง). ูู ุชู ุฑูู ู ูุซูู ุจุฃูุตุงู ูุงุถุญุฉ ุจุงูุฅูุฌููุฒูุฉ ูุงูุนุฑุจูุฉ.
โ ๏ธ Important Note | ู ูุงุญุธุฉ ู ูู ุฉThis repository is different from programming-language repos (like Python/Go/Rust) where every exercise is a standalone, runnable file. Here, exercises are split into two distinct types:
Type ุงูููุน Executable? ูุงุจู ููุชูููุฐุ Design Exercises ุชู ุงุฑูู ุงูุชุตู ูู โ No โ ูุง SQL Exercises ุชู ุงุฑูู SQL โ Yes โ ูุนู Each type has its own template. See the Templates section below.
ูุฐุง ุงูู ุณุชูุฏุน ู ุฎุชูู ุนู ู ุณุชูุฏุนุงุช ูุบุงุช ุงูุจุฑู ุฌุฉ ุญูุซ ูู ุชู ุฑูู ููุณ ุจุงูุถุฑูุฑุฉ ููุฏุงู ูุงุจูุงู ููุชุดุบูู. ุชู ุงุฑูู ุงูุชุตู ูู ู ุฎุฑุฌุงุชูุง ุชุญููู ูู ุฎุทุทุงุชุ ุจููู ุง ุชู ุงุฑูู SQL ูู ุงุณุชุนูุงู ุงุช ุชูููุฐ ู ุจุงุดุฑุฉ. ููู ููุน ูุงูุจ ุฎุงุต ุจู โ ุงูุธุฑ ูุณู ุงูููุงูุจ ุฃุฏูุงู.
learn-database-by-practice/
โโโ .gitignore # Git ignore file | ู
ูู ุชุฌุงูู ุงูุฌูุช
โโโ README.md # Project overview | ูุธุฑุฉ ุนุงู
ุฉ ุนูู ุงูู
ุดุฑูุน
โโโ template-design.md # Design problem template | ูุงูุจ ุชู
ุงุฑูู ุงูุชุตู
ูู
โโโ template-sql.sql # SQL problem template | ูุงูุจ ุชู
ุงุฑูู SQL
โ
โโโ theory/ # Short concept references | ู
ุฑุฌุน ู
ุฎุชุตุฑ ููู
ูุงููู
โ โโโ 01_fundamentals.md
โ โโโ 02_design.md
โ โโโ 03_ddl.md
โ โโโ 04_dml.md
โ โโโ 05_dql_joins.md
โ โโโ 06_aggregation.md
โ โโโ 07_subqueries.md
โ โโโ 08_window_functions.md
โ โโโ 09_dcl_tcl.md
โ โโโ 10_indexing.md
โ โโโ 11_advanced.md
โ
โโโ problems/ # All exercises | ุฌู
ูุน ุงูุชู
ุงุฑูู
โโโ design/ # Design exercises | ุชู
ุงุฑูู ุงูุชุตู
ูู
โ โโโ 0001_normalize_table/
โ โ โโโ main.md
โ โโโ 0002_er_diagram_from_requirements/
โ โ โโโ main.md
โ โโโ ...
โ
โโโ sql/ # SQL exercises | ุชู
ุงุฑูู SQL
โโโ 0001_create_simple_table/
โ โโโ main.sql
โโโ 0002_inner_join_basics/
โ โโโ main.sql
โโโ ...
Why two problem folders? | ูู
ุงุฐุง ููุฌุฏ ู
ุฌูุฏูู ููุชู
ุงุฑููุ
Design exercises produce an analysis or diagram, not runnable code โ while SQL exercises (DDL, DML, DQL, joins, aggregation, subqueries, window functions, DCL/TCL, indexing, advanced objects) are all executed the same way, and often mix several topics in a single query. So design/ is kept separate, while all SQL topics stay flat under sql/ instead of being split into sub-folders per topic.
ุชู
ุงุฑูู ุงูุชุตู
ูู
ู
ุฎุฑุฌุงุชูุง ุชุญููู ุฃู ู
ุฎุทุทุ ูููุณุช ููุฏุงู ูุงุจูุงู ููุชูููุฐ โ ุจููู
ุง ุชู
ุงุฑูู SQL (DDL, DML, DQLุ ุงูุฌูููุฒุ ุงูุชุฌู
ูุนุ ุงูุงุณุชุนูุงู
ุงุช ุงููุฑุนูุฉุ ุฅูุฎ) ูููุง ุชูููุฐ ุจููุณ ุงูุทุฑููุฉุ ูุบุงูุจูุง ู
ุง ุชุฏู
ุฌ ุนุฏุฉ ู
ูุงุถูุน ูู ุงุณุชุนูุงู
ูุงุญุฏ. ูุฐูู ุชู
ูุตู design/ุ ุจููู
ุง ุจููุช ู
ูุงุถูุน SQL ู
ุณุทุญุฉ ุฏุงุฎู sql/ ุจุฏูุงู ู
ู ุชูุณูู
ูุง ุฅูู ู
ุฌูุฏุงุช ูุฑุนูุฉ ููู ู
ูุถูุน.
- A relational database installed โ PostgreSQL is used by default (Download)
- ูุงุนุฏุฉ ุจูุงูุงุช ุนูุงุฆููุฉ ู ุซุจุชุฉ โ ููุณุชุฎุฏู PostgreSQL ุงูุชุฑุงุถููุง
psql --version# Clone the repository | ุงุณุชูุณุงุฎ ุงูู
ุณุชูุฏุน
git clone https://github.com/AbdullahNamespace/learn-database-by-practice.git
cd learn-database-by-practice
# Run a specific SQL problem against your database | ุชุดุบูู ุชู
ุฑูู SQL ู
ุญุฏุฏ ุนูู ูุงุนุฏุฉ ุจูุงูุงุชู
psql -U your_user -d your_database -f problems/sql/0001_create_simple_table/main.sqlDesign problems don't execute โ open main.md, read the requirements, and write your analysis, normalized schema, or ER diagram directly in the file (or link an image/diagram file next to it).
ุชู
ุงุฑูู ุงูุชุตู
ูู
ูุง ุชูููุฐ โ ุงูุชุญ main.mdุ ุงูุฑุฃ ุงูู
ุชุทูุจุงุชุ ูุงูุชุจ ุชุญูููู ุฃู ุงูู
ุฎุทุท ุงูู
ุทุจูุน ุฃู ู
ุฎุทุท ER ู
ุจุงุดุฑุฉ ูู ุงูู
ูู (ุฃู ุฃุถู ุฑุงุจุทุงู ูุตูุฑุฉ/ู
ูู ู
ุฎุทุท ุจุฌุงูุจู).
This repo uses two templates, since design and SQL exercises are fundamentally different in nature: ูุณุชุฎุฏู ูุฐุง ุงูู ุณุชูุฏุน ูุงูุจููุ ูุฃู ุชู ุงุฑูู ุงูุชุตู ูู ูุชู ุงุฑูู SQL ู ุฎุชููุฉ ุฌููุฑูุงู ูู ุทุจูุนุชูุง:
template-design.mdโ for design/analysis exercises (normalization, ER modeling, relationships) | ูุชู ุงุฑูู ุงูุชุตู ูู /ุงูุชุญูููtemplate-sql.sqlโ for executable SQL exercises (DDL, DML, DQL, joins, etc.) | ูุชู ุงุฑูู SQL ุงููุงุจูุฉ ููุชูููุฐ
See each file for the full format. | ุงูุธุฑ ุฅูู ูู ู ูู ูู ุนุฑูุฉ ุงูุตูุบุฉ ุงููุงู ูุฉ.
Happy Learning! ๐๏ธ | ุชุนููู ุณุนูุฏ!