What is a trigger in SQL ?

A trigger is a stored program in a database which automatically gives responses to an event of DML operations done by insert, update, or delete. In other words, is nothing but an auditor of events happening across all database tables.

Let’s look at an example of a trigger :


CREATE TRIGGER bank_trans_hv_alert
	BEFORE UPDATE ON bank_account_transaction
	FOR EACH ROW
	begin
	if( abs(:new.transaction_amount)>999999)THEN
    RAISE_APPLICATION_ERROR(-20000, 'Account transaction exceeding the daily deposit on SAVINGS account.');
	end if;
	end;
What is a trigger in SQL ?

Published on 16-Dec-2021 16:46:22

You may also like this!