Introduction
Foreign keys
7. Creating tables with foreign keys
Multicolumn foreign keys
Updates and deletes
Revision

Instruction

Okay. Now that we know what we need to keep our data consistent, let's create the tables again - this time, with a foreign key.

When creating the table project, we will put the following new line:

FOREIGN KEY(manager_id) REFERENCES employee(id)

This means that the column manager_id points to the column id in the table employee. From now on, the manager_id column is a foreign key. In other words, it will not allow values other than those which we can find in the column employee.id.

Exercise

The table employee is already there. Run the template code to create the table project.

Console

Code editor

Result

TableConsole