0% found this document useful (0 votes)
21 views5 pages

Triggers

Triggers are SQL statements that automatically execute in response to database modifications, serving purposes such as auditing changes and ensuring data integrity. There are various types of triggers, including row-level and statement-level triggers, as well as before and after triggers for different operations like INSERT, UPDATE, and DELETE. Triggers can be created and deleted using the CREATE TRIGGER and DROP TRIGGER statements, respectively.

Uploaded by

lokibeaver
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views5 pages

Triggers

Triggers are SQL statements that automatically execute in response to database modifications, serving purposes such as auditing changes and ensuring data integrity. There are various types of triggers, including row-level and statement-level triggers, as well as before and after triggers for different operations like INSERT, UPDATE, and DELETE. Triggers can be created and deleted using the CREATE TRIGGER and DROP TRIGGER statements, respectively.

Uploaded by

lokibeaver
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 5

TRIGGERS

 Trigger is a SQL statement, which is executed


automatically by the system when there is a
modification done in the database.

 Triggers are useful mechanisms for alerting humans


or for performing certain tasks automatically when
certain conditions are met.
Uses of triggers :-
 Triggers are used to audit changes to the database.
 They are used to ensure the integrity of data.
 They can undo an attempt to change data.
 Types of Triggers :-
There are 12 basic types of triggers are available.
Few are :-
i) Row level Trigger – Trigger once for each row in a transaction. We
can create a row-level trigger by using “FOR EACH ROW” clause in the
CREATE TRIGGER.
ii) Statement level Trigger – This executes once for each
transaction. (Eg., If a single transaction inserted 700 rows into a table ,
then a statement level trigger on that table will be executed only once). It is
the default type of triggers created using CREATE TRIGGER.
iii) Before and after trigger :- Before trigger fires before executing
triggering statement. (i.e INSERT,UPDATE,DELETE commands) ; After
trigger fires after executing triggering statement. (i.e INSERT, UPDATE,
DELETE commands)
Some valid trigger types are,
1. Before insert row
2. Before insert statement
3. After insert row
4. After insert statement
5. Before update row
6. Before update statement
7. After update row
8. After update statement
9. Before delete row
10. Before delete statement
11. After delete row
12. After delete statement
 Creating a Trigger :-
 Triggers are created using CREATE TRIGGER statement.
Syntax :-
CREATE TRIGGER trigger_name
{BEFORE|AFTER}
{INSERT|DELETE|UPDATE}
ON table_name
[FOR EACH ROW] [WHEN condition]
[PL/SQL block];
Simple Example to create a trigger for salary update,
CREATE TRIGGER salary_update
BEFORE UPDATE ON employee_details
BEGIN
dbms_output.put_line (‘ Employee record updated ‘);
END;
/
Trigger created.
> update employee_details set salary = salary * 0.5 where salary < = 10000;
> select * from emplyee_details ;
 Deleting a Trigger :-
To destroy the trigger, DROP TRIGGER statement is used,
Syntax :-
DROP TRIGGER trigger_name;
Example.,
DROP TRIGGER Salary_update;

You might also like