Loading lesson path
Concept visual
Start at both ends
Overview
constraint establishes a link between two tables, and prevents action that will destroy the link between them.
is a column in a table that refers to the PRIMARY KEY in another table. The table with the foreign key column is called the child table, and the table with the primary key column is called the referenced or parent table.
constraint prevents invalid data from being inserted into the foreign key column (in the child table), because the value has to exist in the parent table.
constraint also prevents you from deleting a record in the parent table, if related rows still exist in the child table.
30
23
22456
24562
Here we see that the "PersonID" column in the "Orders" table points to the "PersonID" column in the "Persons" table. The "PersonID" column in the "Persons" table is the PRIMARY KEY in the "Persons" table. The "PersonID" column in the "Orders" table is the FOREIGN KEY in the "Orders" table.
constraint on the "PersonID" column upon creation of the "Orders" table:
( OrderID int PRIMARY KEY, OrderNumber int NOT NULL, PersonID int, CONSTRAINT fk_Person FOREIGN KEY (PersonID)
);