1. A row-level trigger in Oracle is a trigger that fires once for each row affected by a DML operation (INSERT, UPDATE, DELETE) on a table, rather than once per SQL statement.
2. Row-level triggers can access the :NEW and :OLD pseudo-records. :NEW holds the new values being inserted or updated, while :OLD holds the previous values before an update or delete.
3. They are defined using FOR EACH ROW in the CREATE TRIGGER statement, which is mandatory for a trigger to operate at the row level.
4. Row-level triggers can be used to enforce complex business rules, such as checking values before insert/update, maintaining audit logs, or automatically computing derived columns.
5. They can be BEFORE or AFTER triggers. A BEFORE trigger executes before the DML operation affects the row, allowing modification of :NEW values. An AFTER trigger executes after the row has been modified in the table.
6. Row-level triggers can prevent DML operations by raising exceptions. For example, you can prevent a salary update if it exceeds a limit using RAISE_APPLICATION_ERROR.
7. They can cause cascading effects, so care is needed to avoid mutating table errors when a trigger tries to modify the same table it is defined on. Oracle restricts certain operations to prevent this.
8. Row-level triggers are fired automatically and cannot be called explicitly; they are tightly coupled with DML operations on the table they are defined on.
9. They are often used for auditing purposes, for example, recording who updated a row and when by inserting a record into an audit table every time a row changes.
10. Performance can be impacted if the trigger has complex logic or affects many rows, because it executes individually for each row; optimization and careful design are crucial.
No comments:
Post a Comment