

The parent table in the employed-by relationship is the DEPT table. For any given referential constraint, the parent table is the table that contains the primary key and the child table is the table that contains the foreign key. Two other important RI terms are parent and child tables. The rules that accompany the RI definition are just as important as the relationship. The combination of the relationship and the rules attached to that relationship is referred to as a referential constraint. Acceptable is defined in terms of an appropriate value as housed in the corresponding primary key, or a null. The concept of RI is summarized in the following "quick and dirty" definition: RI is a guarantee that an acceptable value is always in the foreign key column. In general, a foreign key must always either contain a value within the domain of foreign key values (values currently in the primary key column), or be set to null. The set of RI rules, applied to each relationship, determines the status of foreign key columns when inserted or updated, and of dependent rows when a primary key row is deleted or updated. The combination of the primary and foreign key columns and the rules that dictate the data that can be housed in those columns is the very beginning of understanding and utilizing RI to ensure correct and useful relational databases. RI appropriately embodies the integrity and usability of a relationship by establishing rules that govern that relationship. Of course, the identification of the primary and foreign keys that constitutes a relationship between tables is a component of defining referential integrity. Many people tend to over-simplify RI stating that it is merely the identification of relationships between relational tables. Referential integrity is a method for ensuring the "correctness" of data within a DBMS.
#REFERENTIAL INTEGRITY CODE#
#REFERENTIAL INTEGRITY HOW TO#

Referential Integrity in Microsoft SQL Server

When you create a relationship between two tables, it is usually a good idea to enforce referential integrity.
