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

Great! You can also show foreign keys in ERD diagrams. To do that, we use the abbreviation FK. For instance, the ERD for the table you've just created can look as follows:

Employee and department tables

As you can see, manager_id is a foreign key in this table because it's marked with FK. There is a line between the table department and the table employee because there is a connection between them - the column manager_id in the table department points to the table employee.

Exercise

Our database is getting bigger. We now have another table position which will store information about various positions available in a given department. Use the ERD below to create the proper table.

Department and position tables

Stuck? Here's a hint!

Type:

CREATE TABLE position (
  id int  PRIMARY KEY,
  title varchar(255)  NOT NULL,
  department_id int  NOT NULL,
  FOREIGN KEY (department_id)
  REFERENCES department (id)
);