为什么要用触发器?DROP TABLE
Name
DROP TABLE -- remove a table
Synopsis
DROP TABLE name [, ...] [ CASCADE | RESTRICT ]
Description
DROP TABLE removes tables from the database. Only its owner may destroy a table. To empty a table of rows, without destroying the table, use DELETE. DROP TABLE always removes any indexes, rules, triggers, and constraints that exist for the target table. However, to drop a table that is referenced by a foreign-key constraint of another table, CASCADE must be specified. (CASCADE will remove the foreign-key constraint, not the other table entirely.) 

解决方案 »

  1.   

    触发器 分两部来做,1.建立一个函数,当向一个表A插入\删除\修改记录时 会运行 的函数
    这个函数是执行你的动作(对另一个表B的操作)的函数,返回值是 trigger 
    2.实现触发器,这个动作是去调用 开始建立的触发器函数 , 要说明是在对A表操作之前还是之后 去调用那个函数CREATE FUNCTION a_trigger_fun() RETURNS trigger AS ' 
    begin
    insert into b values(new.f1,new.f2,new.f3,new.f4,new.f5);
    return new; 
    end;'  LANGUAGE 'plpgsql' VOLATILE;
    CREATE TRIGGER a_intrigger AFTER INSERT ON a FOR EACH ROW EXECUTE PROCEDURE a_trigger_fun();
      

  2.   

    目前postgres尚不支持sql级触发器,所以是个遗憾,不过pl/pgsql的威力也是巨大的。