Home

Compound triggers should define at least two triggers

Description

    Compound triggers are a type of trigger in PL/SQL that allow multiple triggers to be defined for a single table. The rule states that compound triggers should define at least two triggers. This means that when a compound trigger is created, it must include two or more triggers that will be triggered when a certain event occurs. This allows for more complex logic to be implemented when a certain event occurs, such as updating multiple tables or performing multiple operations. Compound triggers can be used to simplify and streamline the code needed to perform complex operations when a certain event occurs.

Key Benefits

  • Increased Efficiency: Compound triggers allow for multiple triggers to be set up at once, resulting in increased efficiency and reduced complexity.
  • Reduced Complexity: By setting up multiple triggers at once, Compound triggers reduce the need for complex logic when setting up rules, resulting in a simpler and more streamlined process.

 

Non-compliant Code Example

CREATE TRIGGER trgCustomerAdded 
FOR INSERT 
ON CUSTOMERS
COMPOUND TRIGGER    --Non compliant code (Compound trigger with only one trigger)
BEFORE EACH ROW IS 
BEGIN
:new.minimunExpense:= 2000;
END BEFORE EACH ROW;
END trgCustomerAdded;

Compliant Code Example

CREATE TRIGGER trgCustomerAdded 
FOR INSERT 
ON CUSTOMERS
COMPOUND TRIGGER    --Compliant code (Compound trigger with more than one trigger)
BEFORE EACH ROW IS 

BEGIN
:new.minimunExpense:=2000;
END BEFORE EACH ROW;

AFTER EACH ROW IS
BEGIN
INSERT INTO CUSTOMERS VALUES('PQR',�ABC�,3000,9328491037); 
COMMIT;
END AFTER EACH ROW;

END trgCustomerAdded;
Visual Expert 2024
 VEPLSQLRULE108