Tuesday, 18 March 2014

Difference between Triggers and Constraints?

Triggers support all of the functionality of constraints. But constraints are automatically enforced by the database engine and require less overhead than do triggers. Therefore, constraints should be used if possible, unless the application needs are more complex than can be enforced by constraints.
Enforcing entity integrity should always be done using constraints. Entity integrity refers to the uniqueness of rows. Primary keys and unique constraints are nearly always the best way of enforcing entity integrity.

When evaluating the use of constraints or triggers, always use constraints if they can meet the functional needs of the application. A trigger should be considered if custom error messages are required in response to error conditions, or in situations where more complex logic is required than constraints can provide.

No comments:

Post a Comment