Loading lessons...
The Sample Database
The Sample Database
Most of the examples in this course use two small tables you should memorize: Customers and Orders.
The Customers table
| CustomerID | CustomerName | ContactName | Country |
|---|---|---|---|
| 1 | Alfreds Futterkiste | Maria Anders | Germany |
| 2 | Ana Trujillo | Ana Trujillo | Mexico |
| 3 | Antonio Moreno | Antonio Moreno | Mexico |
| 4 | Around the Horn | Thomas Hardy | UK |
CustomerIDis the primary key - every customer gets a unique number.CustomerNameandContactNameare text.Countryis where the customer lives.
The Orders table
| OrderID | CustomerID | OrderDate |
|---|---|---|
| 10248 | 1 | 2024-01-05 |
| 10249 | 3 | 2024-01-07 |
| 10250 | 1 | 2024-01-10 |
OrderIDis the primary key for orders.CustomerIDlinks each order to a customer - this is a foreign key.- Customer 1 (Alfreds) has two orders here.
How the tables connect
Customers.CustomerID <--> Orders.CustomerID
This relationship is what makes joins possible - more on that later.
Primary key vs foreign key
- Primary key: a column (or columns) that uniquely identifies each row in its own table.
- Foreign key: a column that points to the primary key of another table.
TL;DR
- Customers: CustomerID, CustomerName, ContactName, Country.
- Orders: OrderID, CustomerID, OrderDate.
- Orders.CustomerID references Customers.CustomerID.
- Primary keys identify rows; foreign keys link tables.