Lesson 3 +10 XP

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

CustomerIDCustomerNameContactNameCountry
1Alfreds FutterkisteMaria AndersGermany
2Ana TrujilloAna TrujilloMexico
3Antonio MorenoAntonio MorenoMexico
4Around the HornThomas HardyUK
  • CustomerID is the primary key - every customer gets a unique number.
  • CustomerName and ContactName are text.
  • Country is where the customer lives.

The Orders table

OrderIDCustomerIDOrderDate
1024812024-01-05
1024932024-01-07
1025012024-01-10
  • OrderID is the primary key for orders.
  • CustomerID links 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.