How Triggers and Constraints Differ
Both triggers and constraints can constrain data input, but they differ significantly.
A constraint applies to both existing and new data.
For example, if a database column has a NOT NULL constraint, then its existing data is NOT NULL and no DML statement can violate the NOT NULL constraint.
A trigger applies only to new data. For example, a trigger can prevent a DML statement from inserting a NULL value into a database column,
but the column might contain NULL values that were inserted into the column before the trigger was defined or while the trigger was disabled.
Partager