How to Store MySQL Trigger exception / failure info into Table or in Variables

前端 未结 3 836
自闭症患者
自闭症患者 2021-01-21 11:35

I am stuck at somewhere and I need some help from you.

Scenario

I have two databases i.e., test_db1 and test_db2 and have users

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-21 12:04

    Check out the syntax for DECLARE HANDLER

    http://dev.mysql.com/doc/refman/5.1/en/declare-handler.html

    Also, if you're trying to debug a SP, this might be helpful for you:

    http://www.bluegecko.net/mysql/debugging-stored-procedures/

    Upon trigger you can use something like below :

        CREATE TRIGGER `my_table_AINS` AFTER INSERT ON `my_table` FOR EACH ROW
    BEGIN
        DECLARE EXIT HANDLER FOR SQLEXCEPTION
            RESIGNAL;
        DECLARE EXIT HANDLER FOR SQLWARNING
            RESIGNAL;
        DECLARE EXIT HANDLER FOR NOT FOUND
            RESIGNAL; 
        -- Do the work of the trigger.
    END
    

    Hope this may help you.

提交回复
热议问题