Part 1
🗄️ What is a Database?
The easiest way to understand a database is to picture it as a 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 fraction of a second.
🏛️ What is a database and what does it do?
Definition
A database is an organized collection of information stored electronically. The system that manages the data is called a DBMS (Database Management System) — such as MySQL, SQL Server, or Oracle.
5 Main Roles
1
Storing huge volumes — unlike Excel, which starts to "choke" at a million rows, a database handles billions of rows with ease.
2
Fast retrieval — with SQL you can find a specific value among millions in milliseconds.
3
Security and permissions — defining exactly who can view, edit, and delete data.
4
Data Integrity — preventing duplicates and contradictions (e.g., two customers with the same ID number).
5
Concurrent access — hundreds of users read and write at the same time without "the file getting locked."
🏗️ The Database Hierarchy
From the Highest Level to the Lowest
☁️
Server / Instance — the computer or cloud the software runs on.
🗄️
Database — the main "warehouse." For example: "a sales system."
📁
Schema — a logical division within the warehouse (like departments in a supermarket: customers, finance...).
📋
Tables — the basic units where the data is actually stored.
🔍
Additional objects — Views (saved queries), Procedures (workflows).
📋 Table Structure — the Heart of the Database
Explanation
A table is built as a grid — but unlike Excel, it's rigid: every column has a predefined role and data type.
| Component | Description | Example |
|---|---|---|
| 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 / Record | Represents a single instance of an entity. Each row is one complete "object" | All the details of a specific customer |
| 🔑 Primary Key | A column that must be unique for each 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 |
A Visual Example — the Products Table
| 🔑 ProductID (PK) | ProductName | 🔗 CategoryID (FK) | ListPrice |
|---|---|---|---|
| 101 | Laptop | 1 | 3,500 |
| 102 | Mouse | 2 | 150 |
| 103 | Keyboard | 2 | 250 |
About this example:
• Primary Key: ProductID ensures no two products share the same number
• Foreign Key: CategoryID links to the Categories table — where category 1 = "Computers", 2 = "Peripherals"
• Types: ListPrice is always a number, ProductName is always text
• Primary Key: ProductID ensures no two products share the same number
• Foreign Key: CategoryID links to the Categories table — where category 1 = "Computers", 2 = "Peripherals"
• Types: ListPrice is always a number, ProductName is always text
In summary: a database is the engine behind every app and website you know. It stores information in linked tables and lets you quickly extract complex business insights.
Part 2
🏪 The Northwind Database Structure
Northwind is a classic database that simulates a trading company. It includes 8 central tables linked to one another. This is the database we'll use throughout the 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 the Tables
| From Table | Linked Via | To Table | Meaning |
|---|---|---|---|
| Orders | CustomerID | Customers | Every order belongs to a customer |
| Orders | EmployeeID | Employees | Every order was handled by an employee |
| Orders | ShipVia | Shippers | Every order was shipped by a shipping company |
| Order Details | OrderID | Orders | The line items of each order |
| Order Details | ProductID | Products | Which product was ordered |
| Products | SupplierID | Suppliers | Who supplies the product |
| Products | CategoryID | Categories | Which category the product belongs to |
Tip: the Orders table is the heart of Northwind — it links to 4 other tables. Most of the JOIN queries we write will go through it.
🎯 Your First Query on Northwind
Basic SELECT
Once you connect to Northwind, you can retrieve data:
If you see 5 rows of customers — the database is working perfectly! 🎉
USE Northwind;SELECT * FROM customers LIMIT 5;If you see 5 rows of customers — the database is working perfectly! 🎉
Part 3
🔑 Keys & 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 & Rules
A column (or combination of columns) that identifies each row completely uniquely.
3 rules:
1. No two values can be identical
2. It cannot be NULL
3. It doesn't change over time
Example:
3 rules:
1. No two values can be identical
2. It cannot be NULL
3. It doesn't change over time
Example:
CustomerID in the customers table — every customer has their own unique number.
A Primary Key is the "ID card" of every row in a table — just as no two ID cards can share the same number.
🔗 Foreign Key
Definition
A column in one table that points to a Primary Key in another table. It creates the relationship between the tables.
Example:
Meaning: "every order has a defined customer that can be found in the customers table."
Example:
CustomerID in the orders table points to CustomerID in the customers table.Meaning: "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 keeps the relationships valid.
📊 Types of Relationships
| Relationship Type | Explanation | 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 junction table — many to many | Orders ↔ Products (via Order Details) |
| 1:1 (One-to-One) | One row in table A = one row in table B | Less common — e.g., separate contact details |
🔄 How Does This Relate to JOIN?
The Direct Connection
The JOIN command uses exactly these primary-key/foreign-key relationships to combine tables:
Every JOIN we write combines tables through the columns that define the relationship between them.
JOIN orders ON customers.CustomerID = orders.CustomerIDEvery JOIN we write combines 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.
⚡ Full Comparison
| Criterion | Excel | SQL |
|---|---|---|
| Data volume | up to ~1M rows | billions of rows |
| Speed | slow with large files | very fast at any size |
| Sharing & accessibility | files passed around, conflicting versions | one central database for everyone |
| Data security | anyone can edit | precise permissions per user |
| Human error | easy to enter a wrong value | a rigid structure prevents mistakes |
| Concurrent work | the file locks — one person at a time | hundreds of users at once |
| Visual flexibility | charts and colors with ease | requires a separate BI tool |
| Accessibility for the average user | an intuitive graphical interface | requires learning a language |
| Precise retrieval | loads the whole file into memory | retrieves only what's needed |
🎯 When to Use Each One?
Use Excel When You Want
✅ A one-off analysis of small files (up to a few hundred thousand rows)
✅ Quick visualization — charts, Pivot Tables
✅ Working with data already exported from the database
✅ Easy sharing with managers who don't know SQL
✅ Quick 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
✅ Maintaining the "single source of truth" — correct, centralized data
✅ Automation and running repeated processes
✅ Complex queries that join multiple tables
✅ Reports that refresh automatically
✅ Maintaining the "single source of truth" — correct, centralized data
✅ Automation and running repeated processes
In practice: analysts use SQL to pull data from the database — then bring it into Excel, Power BI, or Python for analysis and visualization. The two complement each other!
📈 Conclusion — Why Learn SQL?
3 Key Reasons
1
A universal language — SQL works with MySQL, SQL Server, Oracle, PostgreSQL, and more. Learn it once — use it everywhere.
2
Market demand — SQL is one of the most sought-after skills in any Data, BI, Analytics, or Product role.
3
Analytical independence — instead of waiting for IT to prepare a report, you pull the data you need exactly when you need it.