- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathig_triggers.sql
More file actions
Latest commit
23 lines (17 loc) · 536 Bytes
/
Copy pathig_triggers.sql
File metadata and controls
23 lines (17 loc) · 536 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
DELIMITER $$
CREATETRIGGERprevent_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 be a follower of Yourself';
END IF;
END;
CREATETRIGGERlogs_unfollowEvent
AFTER DELETEON follows FOR EACH ROW
BEGIN
INSERT INTO unfollows(follower_id,followee_id) VALUES (OLD.follower_id, OLD.followee_id); -- INSERT INTO unfollows SET follower_id = OLD.follower_id, followee_id = OLD.followee_id;
END;
$$
DELIMITER ;