在postgres中的另一个孩子中级联删除孩子

时间:2019-05-22 16:02:21

标签: postgresql

如果在Postgresql中通过表C连接到表A的表B中的行被删除,那么如何删除表A中的行?

CREATE FUNCTION delete_training() RETURNS trigger AS
$$
BEGIN
    delete
    from trainings
    where id in (
        select t.id
        from roots
                 inner join dictionaries d on roots.dictionary_id = d.id
                 inner join trainings t on roots.training_id = t.id
        where d.id = old.id);
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER trigger_delete_training
    BEFORE DELETE
    ON dictionaries
EXECUTE PROCEDURE delete_training();

0 个答案:

没有答案