0% found this document useful (0 votes)
11 views2 pages

SQL Trigger

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

SQL Trigger

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

DELIMITER //

CREATE TRIGGER update_film_last_update


AFTER INSERT ON film_text
FOR EACH ROW
BEGIN
UPDATE film
SET last_update = NOW()
WHERE film.film_id = NEW.film_id;
END;
//

DELIMITER ;

CREATE DEFINER=`root`@`localhost`
TRIGGER `hobby_AFTER_INSERT` AFTER INSERT ON `hobby`
FOR EACH ROW BEGIN
INSERT INTO `practice`.`emp` (`Emp_id`, `name`, `salary`, `mail`) VALUES ('03',
'Tejaswini', '57000', '[email protected]');
END

DELIMITER //

CREATE TRIGGER update_film_last_update


AFTER INSERT ON film_text
FOR EACH ROW
BEGIN
UPDATE film
SET last_update = NOW()
WHERE film.film_id = NEW.film_id;
END;

DELIMITER ;

-----------------------------------------------------------------------------------
-------------------

CREATE TRIGGER film_delete_trigger AFTER DELETE ON film FOR EACH ROW


DELETE FROM film_actor WHERE film_id = OLD.film_id;

This trigger will delete all rows from the film_actor table whenever a row is
deleted from the film table.
This ensures that the two tables remain in sync and that there are no orphaned rows
in the film_actor table.

-----------------------------------------------------------------------------------
---------------------------

CREATE TRIGGER customer_update_trigger BEFORE UPDATE ON customer FOR EACH ROW


IF NEW.active = 0 THEN
SET NEW.create_date = CURRENT_TIMESTAMP;
END IF;

This trigger will update the create_date column in the customer table to the
current timestamp whenever the active column is set to 0.
This can be useful for tracking when customers were deactivated.

-----------------------------------------------------------------------------------
------------------------

You might also like