1
2-- Trigger to update donatiom count in donor table whenever
3-- A new donation is made by that person
4
5CREATE or REPLACE FUNCTION increase_count()
6RETURNS TRIGGER
7AS
8$$
9BEGIN
10 UPDATE donor SET dcount = dcount + 1 WHERE did = NEW.did;
11END
12$$
13LANGUAGE plpgsql;
14
15
16
17CREATE TRIGGER update_donation_count AFTER INSERT ON donation
18FOR EACH ROW
19EXECUTE PROCEDURE increase_count();
20
1CREATE OR REPLACE FUNCTION function_copy() RETURNS TRIGGER AS
2$BODY$
3BEGIN
4 INSERT INTO
5 table2(id,name)
6 VALUES(new.id,new.name);
7
8 RETURN new;
9END;
10$BODY$
11language plpgsql;
1CREATE TRIGGER trig_copy
2 AFTER INSERT ON table1
3 FOR EACH ROW
4 EXECUTE PROCEDURE function_copy();