Professional Documents
Culture Documents
Data Integrity
Overview
Domain Integrity
(columns)
Referential Integrity
(between tables or columns of the
same table)
How Data Integrity is Enforced
DEFAULT Constraints
CHECK Constraints
PRIMARY KEY Constraints
UNIQUE Constraints
FOREIGN KEY Constraints
Cascading Referential Integrity
DEFAULT Constraints
NO ACTION CASCADE
Customers Customers
CustomerID (PK) CustomerID (PK)
1 1
INSERT new UPDATE CustomerID
CustomerID
CASCADE
Orders
2 CustomerID (FK)
Customers
CustomerID (PK)
3
DELETE old
CustomerID
Lesson: Disabling Constraints
Defaults
Rules
Defaults
Considerations:
Defined once, can be bound to one or more columns or
user-defined data types
Rules on the column validates the value of a default
Check constraints on the column validates the value of a
default.
Considerations:
Defined once, can be bound to one or more columns or
user-defined data types
Can contain any expression valid in a WHERE clause
A column or user-defined data type can have only one
rule that is bound to it.
Declarative Integrity
Use for fundamental integrity logic, such as:
When enforcing valid values
Maintaining the relationships between tables
Triggers Or Stored Procedures
Use to maintain complex redundant data that is not part
of a primary or foreign key relationship
Comparison Matrix
Defaults and
Low Low Before
rules
Data types,
Low Low Before
Null/Not Null