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