0% found this document useful (0 votes)
8 views6 pages

Lab7 Triggers

A trigger is an automatic procedure that executes in response to data modification events on a table, unlike stored procedures which must be invoked manually. Key differences include that triggers cannot accept parameters or be executed directly, and transactions cannot be committed or rolled back within them. The document also provides examples of creating two triggers for inserting and deleting records in a faculty table, which log actions to a backup table.

Uploaded by

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

Lab7 Triggers

A trigger is an automatic procedure that executes in response to data modification events on a table, unlike stored procedures which must be invoked manually. Key differences include that triggers cannot accept parameters or be executed directly, and transactions cannot be committed or rolled back within them. The document also provides examples of creating two triggers for inserting and deleting records in a faculty table, which log actions to a backup table.

Uploaded by

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

A trigger is called a special procedure because it cannot be called directly like a stored

procedure. The key distinction between the trigger and procedure is that a trigger is called
automatically when a data modification event occurs against a table. A stored procedure,
on the other hand, must be invoked directly.

The following are the main characteristics that distinguish triggers from stored procedures:

o We cannot manually execute/invoked triggers.


o Triggers have no chance of receiving parameters.
o A transaction cannot be committed or rolled back inside a trigger.
delimiter $$
drop trigger if exists facultydata1 $$
create trigger facultydata1
before insert on faculty for each row
begin
insert into faculty_backup set action='insert',new_id=new.id,date=now();
end $$
delimiter ;
delimiter $$
drop trigger if exists facultydata2 $$
create trigger facultydata2
before delete on faculty for each row
begin
insert into faculty_backup set action='delete',old_id=old.id,date=now();
end $$
delimiter ;

You might also like