← Home page
📖 Study material
🏠 Home 🎯 Comprehensive practice 📚 Study material ✏️ Exercises 🧠 quiz
📖 Organized study material

Study material — SQL Course

In-depth explanations of databases, the Northwind structure, and SQL fundamentals

Part 1
🗄️ What is a database?
To understand what a database is, it's easiest to picture it asA huge, sophisticated digital library. While an Excel file is like a single sheet of paper, a database is the structure that holds thousands of "notebooks", keeps them organized, and lets you find information in a split second.
🏛️ What is a database and what does it do?
definition
A database is An organized collection of data stored electronically. The system that manages the data is called DBMS (Database Management System) — like MySQL, SQL Server, or Oracle.
5 main roles
1
Storing massive quantities — unlike Excel, which starts "hitting a wall" at a million rows, a database handles Billions of rows easily.
2
Fast retrieval — with SQL you can find a specific piece of data out of millions Within milliseconds.
3
Security and permissions — determining exactly who can view, edit, and delete information.
4
Data Integrity — preventing duplicates and contradictions (for example, two customers with the same ID number).
5
Working in parallel — hundreds of users read and write simultaneously without "the file locking".
🏗️ The database hierarchy
From high level to low
☁️
Server (Server/Instance) — the computer or cloud the software runs on.
🗄️
Database — the main \"warehouse\". For example: \"Sales system\".
📁
Schema (Schema) — a logical division within the warehouse (like departments in a supermarket: customers, finance...).
📋
Tables (Tables) — the basic units in which the data is actually stored.
🔍
Additional objects — Views (saved queries), Procedures (workflows).
📋 Table structure — the heart of the database
explanation
The table is built as a Grid — but unlike Excel, it rigid: every column has a predefined role and data type.
componentdescriptionexample
Column (Column/Field) Defines the data type. Every column has a name and a type (number, text, date) a "customer name" or "product price" column
Row (Row/Record) Represents a single instance of an entity. Every row is one complete "object" All the details of a specific customer
🔑 Primary Key A column that must be unique for every row — the record's "ID card" CustomerID
🔗 Foreign Key A column that links to a primary key in another table — creates relationships between tables CustomerID in the Orders table
Visual example — Products table
🔑 ProductID (PK) ProductName 🔗 CategoryID (FK) ListPrice
101Laptop13,500
102Mouse2150
103Keyboard2250
💡
Explanation of the example:
• Primary Key: ProductID ensures no two products share the same number
• Foreign Key: CategoryID links to the Categories table — there it states that category 1 = \"Computers\", 2 = \"Peripherals\"
• types: ListPrice is always a number, ProductName is always text
🎯
to summarize: A database is the engine behind every app and website you know. It stores data in linked tables, and lets you pull complex business insights quickly.
Part 2
🏪 Structure of the Northwind database
Northwind is a classic database that simulates Trading company. It includes 8 core tables linked to one another. This is the database we'll use throughout the entire course.
🗂️ The 8 Tables of Northwind
📊 Table structure — Northwind
🏢 Customers
🔑 CustomerID
CompanyName
ContactTitle
Address
City
Region
PostalCode
📦 Orders
🔑 OrderID
🔗 CustomerID
🔗 EmployeeID
OrderDate
RequiredDate
ShippedDate
🔗 ShipVia
Freight
ShipCity
ShipCountry
📋 Order Details
🔑 OrderID
🔗 ProductID
UnitPrice
Quantity
Discount
🛒 Products
🔑 ProductID
ProductName
🔗 SupplierID
🔗 CategoryID
UnitPrice
UnitsInStock
Discontinued
👤 Employees
🔑 EmployeeID
LastName
FirstName
Title
BirthDate
Address
City
🏭 Suppliers
🔑 SupplierID
CompanyName
ContactTitle
Address
City
PostalCode
🏷️ Categories
🔑 CategoryID
CategoryName
Description
Picture
🚚 Shippers
🔑 ShipperID
🔗 CompanyName
Phone
🔗 Relationships between tables
from a tablerelationship throughto a tablemeaning
OrdersCustomerIDCustomersEvery order belongs to a customer
OrdersEmployeeIDEmployeesEvery order was handled by an employee
OrdersShipViaShippersEvery order was sent by a shipping company
Order DetailsOrderIDOrdersDetails of every order
Order DetailsProductIDProductsWhich product was ordered
ProductsSupplierIDSuppliersWho supplies the product
ProductsCategoryIDCategoriesWhich category the product belongs to
💡
tip: table of Orders It's the heart of Northwind — it's linked to 4 other tables. Most of the JOIN queries we'll write will pass through it.
🎯 First query on Northwind
Basic SELECT
After connecting to Northwind, you can pull data:

USE Northwind;
SELECT * FROM customers LIMIT 5;

If you see 5 rows of customers — the database is working great! 🎉
Part 3
🔑 Keys and relationships
Keys are the foundation of relationships between tables — they're what turns a collection of separate tables into a real database.
🔑 Primary Key
Definition and rules
A column (or combination of columns) that identifies each row Completely unique.

3 rules:
1. There can't be two identical values
2. Cannot be NULL
3. Does not change over time

example: CustomerID In the customers table — every customer has their own unique number.
💡
Primary Key is "ID card" of every row in the table. Just as two ID cards can't share the same number.
🔗 Foreign Key — foreign key
definition
A column in one table that points to a Primary Key in another table. Creates the relationship between the tables.

example: CustomerID in the orders table points toCustomerID In the customers table.

This means: "every order has a defined customer that can be found in the customers table."
⚠️
Referential Integrity: You can't create an order with a CustomerID that doesn't exist in the customers table. The database enforces referential integrity.
📊 Relationship types
relationship typeexplanationAn example in Northwind
1:N (One-to-Many) One row in table A is linked to many in table B One customer → many orders
N:N (Many-to-Many) Requires a bridge table — many-to-many Order ↔ Products (via Order Details)
1:1 (One-to-One) One row in table A = one row in table B less common — for example separate contact details
🔄 How is this related to JOIN?
The direct context
The JOIN statement uses exactly the primary and foreign key relationships to connect tables:

JOIN orders ON customers.CustomerID = orders.CustomerID

Every JOIN we write connects tables through the columns that define the relationship between them.
🎯
the rule: Before every JOIN, ask yourself — Through which column are the tables linked? The answer is usually the primary/foreign key.
Part 4
📊 SQL vs. Excel
Two excellent tools — but for different uses. Understanding the difference will help you know when to use each one.
⚡ Full comparison
criterionExcelSQL
Amount of data Up to ~1M rows Billions of rows
speed Slow with large files Very fast at any size
Sharing and access Files floating around, different versions One central database for everyone
Data security Anyone can edit Precise permissions for each user
Human errors Easy to enter a wrong value A rigid structure prevents mistakes
Working in parallel File locks — only one at a time Hundreds of users concurrently
Visual flexibility Charts and colors made easy Requires a separate BI tool
Accessibility for a regular user An intuitive graphical interface Requires learning a language
Precise retrieval Loads the entire file into memory Fetches only what's needed
🎯 When to use each one?
Use Excel when you want
✅ One-off analysis of small files (up to a few hundred thousand rows)
✅ Fast visualization — charts, pivot tables
✅ Working with data already exported from the database
✅ Easy sharing with managers who don't know SQL
Use SQL when you want
✅ Working with millions of rows and up
✅ Complex queries that join multiple tables
✅ Reports that refresh automatically
✅ Keeping the "single source of truth" — correct, centralized data
✅ Automation and running repetitive processes
💡
in practice: Analysts use SQL to pull data from the database — and then bring it into Excel, Power BI, or Python for analysis and visualization. The two complement each other!
📈 Conclusion — Why Learn SQL?
3 main reasons
1
A universal language — SQL works with MySQL, SQL Server, Oracle, PostgreSQL and more. Learn it once — work everywhere.
2
Market demand — SQL is one of the most in-demand skills in any Data, BI, Analytics and Product role.
3
Analytical independence — instead of waiting for IT to prepare a report for you, you pull the data you need exactly when you need it.