Overview of Referential Integrity (Visual Database Tools)

Referential integrity is a system of rules that ensure relationships between rows in related tables are valid and that you do not accidentally delete or change related data.

Procedure

You can set referential integrity when all of the following conditions are met:

  • The matching column from the primary table is a primary key or has a unique constraint.

  • The related columns in the foreign table have the same data type and size.

When referential integrity is enforced, you must observe the following rules:

  • You cannot enter a value in the foreign-key column of the related table if that value does not exist in the primary key of the related table. However, you can enter a null in the foreign-key column. For example, you cannot indicate that a job is assigned to an employee who is not included in the employee table, but you can indicate that an employee has no assigned job by entering a null in the job_id column of the employee table.

  • You cannot delete a row from a primary key table if rows matching it exist in a related table. For example, you cannot delete a row from the jobs table if there are employees assigned to the job represented by that row in the employee table.

  • You cannot change a primary key value in the primary key table if that row has related rows. For example, you cannot change a row's job_id value in the jobs table if there are employees with that job_id in the employee table.