Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. Table: table_user
  2. userid (primary key)
  3. no_changes_status (true means no update has been made on table_website for this userid)
  4.  
  5. Table: table_website
  6. userid (reference key)
  7. website_url (when the value of this field is changed, no_changes_status should be set to false)
  8.  
  9. DELIMITER $$
  10.  
  11. CREATE TRIGGER testref BEFORE INSERT ON table_website
  12. FOR EACH ROW BEGIN
  13. SELECT @aff_rows:=COUNT(*) FROM table_website WHERE yourCondition = sameConditionUsedForYourInsert
  14. AND (
  15. OLD.col1 != NEW.col1 OR
  16. OLD.col2 != NEW.col2 ...);
  17. IF @aff_rows > 0 THEN
  18. UPDATE table_user SET no_changes_status = whatever WHERE whatever;
  19. END IF;
  20. END;
  21.  
  22. $$
  23. DELIMITER ;
  24.  
  25. SELECT ROW_COUNT();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement