SQL error when trying to create new trigger

后端 未结 1 1314
借酒劲吻你
借酒劲吻你 2021-01-27 12:51

And when I try to create a trigger:

CREATE TRIGGER ctg_el_del 
AFTER DELETE ON ctg
FOR EACH ROW
BEGIN
DELETE FROM ctg
       where ctg.id_ctg = old.lft
                  


        
相关标签:
1条回答
  • 2021-01-27 13:24

    STEP 1 : You need to Create function that returns type Trigger in that function you should mention the SQL Operation like below:

    CREATE FUNCTION trigger_function() RETURNS TRIGGER AS $$
    BEGIN
        DELETE FROM ctg 
        WHERE ctg.id_ctg = old.lft
        AND   ctg.id_ctg = old.rgt;
    END
    $$
    LANGUAGE plpgsql;
    

    STEP 2 : And then create the trigger on the table to call after delete like this:

    CREATE TRIGGER ctg_el_del 
    AFTER DELETE ON ctg
    FOR EACH ROW
    EXECUTE PROCEDURE trigger_function();
    
    0 讨论(0)
提交回复
热议问题