Ensuring data integrity with referential constraints
You use referential constraints to enforce the referential integrity of your database. Referential integrity encompasses all of the mechanisms and techniques that you can use to ensure that your database contains only valid data.
- Adding referential constraints
You can add referential constraints on physical files with no more than one member. A referential constraint is a file-level attribute; therefore, you can create the constraint before the member exists.
- Verifying referential constraints
The system automatically verifies the validity of a referential constraint when you add the constraint with the Add Physical File Constraint (ADDPFCST) command. The system verifies that every non-null value in the foreign key matches a corresponding value in the parent key.
- Enabling or disabling referential constraints
You can enable or disable a referential constraint using the Change Physical File Constraint (CHGPFCST) command or iSeries™ Navigator.
- Removing referential constraints
You can remove referential constraints in various ways. The full impact of the removal depends on the constraint you are removing and the certain conditions that surround the constraint.
- Details: Ensuring data integrity with referential constraints
You might want to ensure data integrity with referential constraints for several reasons.
- Example: Ensuring data integrity with referential constraints
Suppose that a database contains an employee file and a department file. You can define a referential constraint to ensure that every employee in the employee file belongs to a corresponding department in the department file.
- Referential integrity terms
A discussion of referential integrity requires an understanding of several terms. These terms are arranged in an order that might help you understand their relationship to each other.
- Referential integrity enforcement
The input/output (I/O) access for a database file that is associated with an established and enabled constraint varies, depending on whether the file contains the parent key or foreign key in the constraint relationship. The system enforces referential integrity on all parent and dependent file I/O requests.
- Constraint states
A file can be in several constraint states.
- Check pending status in referential constraints
Check pending is the condition of a constraint relationship when potential mismatches exist between parent and foreign keys. When the system determines that referential integrity might have been violated, the constraint relationship is marked as check pending.
- Referential integrity and CL commands
Referential integrity affects the characteristics of some CL commands.
Parent topic:
Managing database files