触发错误

时间:2015-03-25 09:14:26

标签: php mysql triggers

DELIMITER $$

USE `airdb`$$

DROP TRIGGER /*!50032 IF EXISTS */ `updateprodaja`$$

CREATE
    /*!50017 DEFINER = 'root'@'localhost' */
    TRIGGER `updateprodaja` BEFORE UPDATE ON `prodaja` 
    FOR EACH ROW BEGIN
        IF ( SELECT podmireno FROM prodaja WHERE id = NEW.id ) > 0 THEN
            SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Error: you got an error'
        END IF;
    END;
$$

DELIMITER ;

得到错误

Error Code: 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 7

1 个答案:

答案 0 :(得分:0)

试试这个你忘了在结束前终止sql查询

DELIMITER $$

USE `airdb`$$

DROP TRIGGER /*!50032 IF EXISTS */ `updateprodaja`$$

    CREATE
        /*!50017 DEFINER = 'root'@'localhost' */
        TRIGGER `updateprodaja` BEFORE UPDATE ON `prodaja` 
        FOR EACH ROW BEGIN
            IF ( SELECT podmireno FROM prodaja WHERE id = NEW.id ) > 0 THEN
                SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Error: you got an error';
            END IF;
        END;
    $$

    DELIMITER ;