Advertisement
elena1234

trigger blank in MySQL

Feb 13th, 2023 (edited)
1,227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.17 KB | Source Code | 0 0
  1. DELIMITER $$
  2. CREATE TRIGGER triger_name
  3.       trigger_time trigger_event ON table_name FOR EACH ROW
  4.       BEGIN
  5.       END;
  6.  
  7. $$
  8.  
  9. DELIMITER ;
  10.  
  11. ############################################################
  12. DELIMITER $$
  13. CREATE TRIGGER prevent_self_follows
  14.       BEFORE INSERT ON follows FOR EACH ROW
  15.       BEGIN
  16.          IF NEW.follower_id = NEW.followee_id
  17.          THEN
  18.             SIGNAL SQLSTATE '45000'
  19.             SET MESSAGE_TEXT = 'You cannot follow yourself!';
  20.           END IF;
  21.       END;
  22.  
  23. $$
  24.  
  25. DELIMITER ;
  26.  
  27.  
  28. ##########################################################
  29. DELIMITER $$
  30. CREATE TRIGGER capture_unfollows
  31.       AFTER DELETE ON follows FOR EACH ROW
  32.       BEGIN
  33.          INSERT INTO unfollows(follower_id, followee_id)
  34.          VALUES(OLD.follower_id, OLD.followee_id);
  35.       END;
  36.  
  37. $$
  38.  
  39. DELIMITER ;
  40.  
  41. ##############################################################
  42. DELIMITER $$
  43. CREATE TRIGGER update_automatically_staff_table_orders_served
  44.       AFTER INSERT ON customer_orders FOR EACH ROW
  45.       BEGIN
  46.           UPDATE staff
  47.           SET orders_served = orders_served + 1
  48.           WHERE staff.staff_id = NEW.staff_id;
  49.       END;
  50.  
  51. $$
  52.  
  53. DELIMITER ;
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement