Referential Integrity in RDBMS


Referential integrity maintains the defined relationships between tables when records are entered or deleted.In SQL Server,referential integrity is based on relationships between foreign keys and primary keys/Unique keys(through FOREIGN KEY and CHECK constraints).
When you enforce referential integrity, SQL Server prevents users from:
1) Adding records to a related table if there is no associated record in the primary table.
2) Changing values in a primary table that result in orphaned records in a related table.
3) Deleting records from a primary table if there are matching related records.
For example, if we have emp and dept tables in our database,the referential integrity is based on the relationship between the foreign key (dept_id) in the emp table and the primary key (dept_id) in the dept table.

No comments:

Post a Comment