Search code examples
mysqljsptriggersinnodb

Triggers to disable and enable foreign key checks


I dont know why this wont work, i insert from jsp to database but those triggers i made wont run how i want if anyone know how to solve this hes my hero :)

delimiter $$
CREATE TRIGGER forkey_ON BEFORE INSERT ON users
FOR EACH ROW
BEGIN
  SET GLOBAL FOREIGN_KEY_CHECKS=0;
END;  $$
delimiter ;

delimiter $$
CREATE TRIGGER forkey_OFF after INSERT ON users
FOR EACH ROW
BEGIN
  SET GLOBAL FOREIGN_KEY_CHECKS=1;
END;  $$
delimiter ; 

Solution

  • Probably the answer is...

    Setting the GLOBAL does not affect current connections. Setting the SESSION may be what you want. It will apply only to the current connections. Did you try that?