Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Foreign keys
Multi-column Foreign Keys
Summary

Instruction

Great! As you might have noticed, it's not that difficult to create a multi-column foreign key. Let's see how it works in practice.

Exercise

It's time to play around with the new foreign key. Take a look at the tables and try the following tasks:

  1. Insert a new department with an office_floor that doesn't exist.
  2. Try to update an existing row in the department table, and change the office_building_name to a value that doesn't exist in the office table.
  3. Update a row in the office table. Change either the floor or the building name and see what happens.

Stuck? Here's a hint!

Here are some example instructions:

  1. INSERT INTO department VALUES
    (10, 'Customer Service', 2, 3, 'Skyline');
  2. UPDATE department
    SET office_building_name = 'Example'
    WHERE office_building_name = 'Zebra';
  3. UPDATE office
    SET floor = 5
    WHERE floor = 3;