Flat file databases cause insertion, deletion and update anomalies. Use of relational databases where primary and foreign keys are used to link tables helps overcome these issues.
A primary key is a field used to uniquely identify every record in the database. Sometimes primary keys are obvious, for example a car license plate could be used to uniquely identify cars. Often, primary keys are less obvious and it is necessary to create a unique value 鈥 often an ID number.
A primary key is a guaranteed way of uniquely identifying each record. In the school example, the primary key used to identify each member of staff in the teacher table is Staff ID.
Foreign key
A foreign key is a primary key from one table that appears in another table to link the two together. The Department ID is the primary key in the Department table that appears as a foreign key in the Staff table to link the two.