Monday 2 July 2012

PRIMARY KEY AND FOREIGN KEY

DEFINE THE PRIMARY KEY
A primary key is the field that uniquely represents each record in a table. These keys must not have null values. Meaning, you must not leave these
keys blank.Each table in the database must have at least one primary key.
There is also another name for a primary key: the unique identifier.
In the student table, student name might not be a good primary key. For example there are two Sulaiman bin Yahya in this school.


DEFINE FOREIGN KEY

A foreign key is the field that matches the primary key in another table. It contains the same data as those of the primary key in the other table.
Foreign key fields are linked to fields in other tables. While a primary key must have unique values, a foreign key may have duplicate values.


THE IMPORTANCE OF THE PRIMARY KEY

A primary key ensures data integrity by uniquely identifying each record.
It helps to avoid duplicating records.
It prevents null values being entered in the unique field.

DIFFERENTIATE BETWEEN THE PRIMARY KEY AND FOREIGN KEY

A foreign key links to a primary key in another table.
While primary keys must have unique values, foreign keys may have duplicate values. These are the differences between the primary key and foreign key.

0 comments:

Post a Comment