What is a Trigger ,types of trigger in sql server

5/8/2022
All Articles

What is a Trigger #types of triggers in sql #,types of trigger in sql #trigger in pl sql ,#ypes of trigger in sql server

What is a Trigger ,types of trigger in sql server

What is a Trigger ?

A Trigger is a code that associated with insert, update or delete operations. The code
is executed automatically whenever the associated query is executed on a table. Triggers
can be useful to maintain integrity in database.

Unlike Stored Procedures, Triggers cannot be called directly. They can only be
associated with queries.

delimiter $$
CREATE TRIGGER Backup BEFORE DELETE ON Myemployee 
FOR EACH ROW
BEGIN
INSERT INTO myemployee_backup
VALUES (OLD.employee_no, OLD.name, 
        OLD.job, OLD.hire_date, OLD.salary);
END; $$
delimiter; 

Here we create a backup table that holds the value of those employees who are no more the employee of the organisation.
 So, we create a trigger named Backup that will be executed before the deletion of any value from the table Myemployee.
 Before deletion, the values of all the attributes of the table employee will be insert in the table Myemployee_backup. 

Article