Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Primary keys
Foreign keys
Updating and deleting with foreign keys
Summary

Instruction

Remember that once we create a FOREIGN KEY, the database will keep track of the connection between those two tables. This means that we won't be able to add a row with a foreign key value that doesn't exist in the other table.

Exercise

We've created the tables employee and project for you. The table project now has the following definition:

CREATE TABLE project (
  id integer PRIMARY KEY,
  name varchar(64),
  description text,
  manager_id integer,
  FOREIGN KEY (manager_id) REFERENCES employee(id)
);

Try to run the template query, which inserts a row into the project table.

As you can see, the query failed – there's no one with id = 4 in the employee table.