0% found this document useful (0 votes)
2 views3 pages

Experiment 4

The document outlines the creation of three SQL triggers for the CUSTOMERS table: one for after an insert, one for after an update, and one for after a delete. Each trigger sets a variable to capture and display salary information related to the operation performed. The document also includes example SQL commands to insert, update, and delete a customer record, followed by selecting the salary difference variable.

Uploaded by

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

Experiment 4

The document outlines the creation of three SQL triggers for the CUSTOMERS table: one for after an insert, one for after an update, and one for after a delete. Each trigger sets a variable to capture and display salary information related to the operation performed. The document also includes example SQL commands to insert, update, and delete a customer record, followed by selecting the salary difference variable.

Uploaded by

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

DELIMITER //

CREATE TRIGGER
after_insert_salary_difference
AFTER INSERT ON CUSTOMERS
FOR EACH ROW
BEGIN
SET @my_sal_diff = CONCAT('salary
inserted is ', NEW.SALARY);
END;
//

INSERT INTO CUSTOMERS


VALUES (35,'suraj',23,'mudhol', 40000.00);

SELECT @my_sal_diff AS SAL_DIFF;


DELIMITER $$
CREATE TRIGGER after_update_salary_difference
AFTER UPDATE ON CUSTOMERS
FOR EACH ROW
BEGIN
DECLARE old_salary DECIMAL(9, 2);
DECLARE new_salary DECIMAL(9, 2);

SET old_salary = OLD.SALARY;


SET new_salary = NEW.SALARY;
SET @my_sal_diff = CONCAT('salary difference after update is ',
NEW.SALARY - OLD.SALARY);
END;
$$

UPDATE CUSTOMERS
SET SALARY = 55000.00 WHERE ID = 35;
SELECT @my_sal_diff AS SAL_DIFF;
Delimiter $$
CREATE TRIGGER
after_delete_salary_difference
AFTER DELETE ON CUSTOMERS
FOR EACH ROW
BEGIN
SET @my_sal_diff = CONCAT('salary
deleted is ', OLD.SALARY);
END;
$$

DELETE FROM CUSTOMERS


WHERE ID = 35;
SELECT @my_sal_diff AS SAL_DIFF;

You might also like