Northwind Database

Stephan RhodesStephan Rhodes
2 min read

To analyze a real world database like Northwind, we need to solve some of the most common problem that everyday database analysts are trying to solve. For example, an operation team needs data about how suppliers interact with products. They don't know if it make sense for single product to move to a single supplier. Some of the member of the operation team are new, thus they are looking for advice from a database analyst. Our job is to analyze the database for them.

The first thing we have to identify is all of the components of the database as well as their relationship between each other. This database has 11 entities which are also denoted as 11 tables. Most of the cardinality relationship is either 1-to-many and many-to-1 relationship. Some of the 1-to-many relationship comes from entities like supplier to product, product to order_details, order_details to order and so on...

Thus for the operation team to be able to do their quarterly report they need to understand these different kind of cardinal relationship.

Here is an example of 4 entities link with few many-to-1 relationship

Table order_details{
  order_id integer [pk]
  product_id integer [ref: > products.product_id] 
  quantity integer
  discount decimal
}

Table products{
  product_id integer [pk]
  product_name text
  supplier_id integer [ref: > suppliers.supplier_id]
  category_id integer
  quantity_per_unit text
  unit_price decimal
  units_in_stock integer
  units_on_order int
  reorder_level integer
  discontinued integer
}

Table suppliers{
  supplier_id integer [pk]
  company_name text
  contact_name text
  contact_title text
  address text
  city text
  region text
  postal_code text
  country text
  phone text
  fax text
  home_page text
}

Table orders{
  order_id integer [ref: < order_details.order_id]
  customer_id text
  employee_id integer
  order_date date
  required_date date
  shipped_date date
  ship_via integer
  freight decimal
  ship_name text
  ship_address text
  ship_city text
  ship_region text
  ship_postal_code text
  ship_country text
}

Open this database design on a new page

One of the line of code involving "ref" is the one that create relationship between table. I'll explain what it does on the next article but basically there are 4 different ways to write this code involving the "ref" term.

0
Subscribe to my newsletter

Read articles from Stephan Rhodes directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Stephan Rhodes
Stephan Rhodes