Primary and Foreign Keys
Primary and Foreign Keys
Primary Keys
The PRIMARY KEY constraint uniquely identifies each record in a database table.
Each table should have a primary key, and each table can have only ONE primary key.
Note: If you use the ALTER TABLE statement to add a primary key, the primary key column(s) must
already have been declared to not contain NULL values (when the table was first created).
Lecturer : Damien Kettle Module : Database Administration
Foreign Keys
A FOREIGN KEY in one table points to a PRIMARY KEY in another table.
Let's illustrate the foreign key with an example. Look at the following two tables:
Note that the "P_Id" column in the "Orders" table points to the "P_Id" column in the "Persons"
table.
The "P_Id" column in the "Persons" table is the PRIMARY KEY in the "Persons" table.
The "P_Id" column in the "Orders" table is a FOREIGN KEY in the "Orders" table.