Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Foreign keys
Multicolumn foreign keys
Updates and deletes
Revision

Instruction

If you had done everything correctly, you shouldn't have been able to perform any of the tasks we prepared. The database keeps all information consistent, just as it does in case of single column foreign keys.

Exercise

Last time we prepared the template code for you, now it's your turn to make it work! Provide the proper code to create the table department shown in the diagram below:

Office and department tables

The columns office_floor and office_building_name should form a single foreign key.

Stuck? Here's a hint!

Type:

CREATE TABLE department (
  id int PRIMARY KEY,
  name varchar(1000)  NOT NULL,
  manager_id int  NOT NULL,
  office_floor int  NOT NULL,
  office_building_name varchar(255)  NOT NULL,
  FOREIGN KEY (office_floor,office_building_name) REFERENCES office (floor,building_name)
);