Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DELIMITER $$
- CREATE TRIGGER triger_name
- trigger_time trigger_event ON table_name FOR EACH ROW
- BEGIN
- END;
- $$
- DELIMITER ;
- ############################################################
- DELIMITER $$
- CREATE TRIGGER prevent_self_follows
- BEFORE INSERT ON follows FOR EACH ROW
- BEGIN
- IF NEW.follower_id = NEW.followee_id
- THEN
- SIGNAL SQLSTATE '45000'
- SET MESSAGE_TEXT = 'You cannot follow yourself!';
- END IF;
- END;
- $$
- DELIMITER ;
- ##########################################################
- DELIMITER $$
- CREATE TRIGGER capture_unfollows
- AFTER DELETE ON follows FOR EACH ROW
- BEGIN
- INSERT INTO unfollows(follower_id, followee_id)
- VALUES(OLD.follower_id, OLD.followee_id);
- END;
- $$
- DELIMITER ;
- ##############################################################
- DELIMITER $$
- CREATE TRIGGER update_automatically_staff_table_orders_served
- AFTER INSERT ON customer_orders FOR EACH ROW
- BEGIN
- UPDATE staff
- SET orders_served = orders_served + 1
- WHERE staff.staff_id = NEW.staff_id;
- END;
- $$
- DELIMITER ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement