Triggers In SQL SERVER 2008
Join the DZone community and get the full member experience.
Join For FreeThe following SQL Code creates a row level trigger
for the customer table that would executed if INSERT or UPDATE or DELETE
operations performed on the CUSTOMER table. This trigger will store the
salary difference between the old values and new values: for Details Triggers in SQL
CREATE OR REPLACE TRIGGER DisplayChanges
BEFORE DELETE OR INSERT OR UPDATE ON customer
FOR EACH ROW WHEN (NEW.ID > 0)
DECLARE Diff number;
BEGIN Diff: =: NEW. Salary – :OLD. Salary;
dbms_output.put_line(‘Diffrence : ‘ || :Diff);
END;
The following SQL Code creates a row level trigger for the customer table that would executed if INSERT or UPDATE or DELETE operations performed on the CUSTOMER table. This trigger will store the salary difference between the old values and new values:
CREATE OR REPLACE TRIGGER DisplayChanges
BEFORE DELETE OR INSERT OR UPDATE ON customer
FOR EACH ROW WHEN (NEW.ID > 0)
DECLARE Diff number;
BEGIN Diff: =: NEW. Salary – :OLD. Salary;
dbms_output.put_line(‘Diffrence : ‘ || :Diff);
END;
Topics:
Opinions expressed by DZone contributors are their own.
Comments