Foreign Keys - The SQL

As we continue to explore databases and ideas, this project will help you practice model databases and relationships, as well as help you get started on your capstone project.

First you will expand you CompanyDatabase to have Departments, Products and Orders. You will be crafting a queries for these new tables.

After that, this weekend is the next big push your final project, work on the HTML and CSS; As well as the database schema.


  • Work with Foreign Keys
  • Craft Queries
  • Further you final project


  • Add a few tables and foreign keys to an existing database
  • Create the Schema for your final project
  • Work on the HTML & CSS for your final project


Install pgcli

  • For Mac you can brew
  • For Windows you need to install python and pip

Explorer Mode

  • In your Company Database, add a table called Departments. Give this a few columns
  • Add a Foreign key call DepartmentId to your Employee Table
  • Add Table Called Products and a table called Orders. Give each table a few columns
  • In our company, 1 Order can have many Products and 1 Product can have many Orders. This will be a Many to Many relationship. Create the tables and foreign keys needed for this to happen
  • Create queries that can do the following:

    • Given a Department Id, Give me all employees in the department
    • Given a Department Name, give me the phone extensions
    • Find all Orders that contain the Product Id of 2
    • Given an OrderId, Display on the OrderNumber, and all the product names
    • Insert a new Product
    • Creating a new Order
    • Adding an Product to an Order
    • Adding a new employee to a department
    • Updating a employee's department
    • Removing a Product from an Order
  • Turn in the above queries as a gist
  • Work on your final project HTML. DO not sleep on this. You have the time and resources to get a good bit of this done this weekend.
  • Complete your first draft of your database schema for your final project.

Adventure Mode

Epic Mode

  • Investigate working with C#/Ruby and Postgres

Additional Resources