Pages

Friday 4 July 2014

SQL Server: ON UPDATE CASCADE

When DBA/Developer includes the ON UPDATE CASCADE clause, it ensures that if a referenced row in the parent table is updated, then the corresponding child rows are updated and referential integrity is maintained. This would ensure that if a user updated the identifier of a WorkOrder, the corresponding rows in the WorkOrderDetail table would also be updated. DBA/Developer should not use a trigger to enforce referential integrity. Triggers should not be used when constraints can accomplish the same task. FOREIGN KEY constraints are used to enforce referential integrity.
DBA/Developer should not create a CHECK constraint on the WorkOrder table. A CHECK constraint is used to restrict the data allowed for a column to specific values. A CHECK constraint consists of a Boolean expression that evaluates to either TRUE or FALSE. If the expression evaluates to TRUE, the value is allowed for the column, and if the expression evaluates to FALSE, the value is not allowed for the column. CHECK constraints can be defined at the table level or column level, but only CHECK constraints defined at the table level can use columns other than the constrained column in the constraint expression. DBA/Developer should not include the WITH CHECK clause in DBA/Developer FOREIGN KEY constraint because this only enables the constraint. By default, FOREIGN KEY and CHECK constraints are enabled when they are created.
DBA/Developer can use the NOCHECK CONSTRAINT clause of the ALTER TABLE statement to temporarily disable a FOREIGN KEY or CHECK constraint if DBA/Developer needs to insert rows that violate the constraint.

No comments:

Post a Comment