Ошибка при создании триггера SQLSTATE[42000]
Ошибка при создании триггера в mysql
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END IF; END' at line 4 (SQL: CREATE TRIGGER tr_Inser_Outer_Id_If_Null_to_Medobjects BEFORE INSERT ON peoples FOR EACH ROW BEGIN IF NEW.outer_id=NULL THEN SET NEW.outer_id=(SELECT max_num FROM (SELECT MAX(outer_id)+1 as max_num FROM `peoples`) AS t2) END IF; END ) [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END IF; END' at line 4 |
возникает из-за того, что операции в условиях
1 2 3 4 |
IF NEW.outer_id=NULL THEN ...; ...; END IF; |
должны заканчиваться «;»
Правильный код должен быть такой:
1 2 3 4 5 6 |
CREATE TRIGGER tr_Inser_Outer_Id_If_Null_to_Medobjects BEFORE INSERT ON `medobjects` FOR EACH ROW BEGIN IF NEW.outer_id IS NULL THEN SET NEW.outer_id=(SELECT max_num FROM (SELECT MAX(outer_id)+1 as max_num FROM `medobjects`) AS t2); END IF; END |