In MySql, you can be enable/disable triggers whenever you want. Just simply follows below guidelines.
Step 1
write the below these lines instead of "begin" in trigger before sql statement every time when you will create the trigger.
thisTrigger: BEGIN
IF ((@TRIGGER_CHECKS = FALSE) OR (@TRIGGER_BEFORE_INSERT_CHECKS = FALSE)) AND (USER() = 'username@host') THEN
LEAVE thisTrigger;
END IF;
username such as root, username(if you are created user)
host such as localhost, ip of server, etc.
Step 2
Whenever you want the enable or disable triggers then use below query in MySql.
1. If you want disable all Before Insert triggers.
SET @TRIGGER_BEFORE_INSERT_CHECKS = FALSE;
2. If you want disable all After Insert triggers.
SET @TRIGGER_AFTER_INSERT_CHECKS = FALSE;
3. If you want disable all Before Update triggers.
SET @TRIGGER_BEFORE_UPDATE_CHECKS = FALSE;
4. If you want disable all After Update triggers.
SET @TRIGGER_AFTER_UPDATE_CHECKS = FALSE;
5. If you want disable all Before Delete triggers.
SET @TRIGGER_BEFORE_DELETE_CHECKS = FALSE;
6. If you want disable all After Delete triggers.
SET @TRIGGER_AFTER_DELETE_CHECKS = FALSE;
7. If you want disable all triggers.
SET @TRIGGER_CHECKS = FALSE;
If you want enable triggers just pass "TRUE" in query.
Cheers!!!
No comments:
Post a Comment