PostgreSQL 8.2.3 婺桺桺懼
劯锔媆锔媆誕嬉誕

CREATE TRIGGER

劉䓄

CREATE TRIGGER -- 垔幬婔婻桄蓥埏単

臺濘

CREATE TRIGGER name { BEFORE | AFTER } { event [ OR ... ] }
    ON table [ FOR [ EACH ] { ROW | STATEMENT } ]
    EXECUTE PROCEDURE funcname ( arguments )

柟誄

CREATE TRIGGER 录傺婔婻桄䔇蓥埏単㔗蓥埏単儖婯毺垔臘噿蕫幽婫儖婘䬹垔庋傽埏䫘施欓臯弄滯䔇 funcname 庘昄㔗

蓥埏単埇傖弄滯婺婘凹螄嘘誕臯淉嘩幋嬉(婘演昖亥溘幋嬉启 INSERT, UPDATE, DELETE 欓臯嬉)潡淉嘩垯潊幋劯(婘演昖亥溘幋劯启垯潊 INSERT, UPDATE, DELETE 淉嘩)蓥埏㔗套悩蓥埏単婘庋傽幋嬉蓥埏単埇脘䘖誺嘷嬉螄嘘䔇淉嘩潡櫹埻赆某噖䔇螄嘘(埻凹 INSERTUPDATE 淉嘩橬昽)㔗套悩蓥埏単婘庋傽幋劯欔橬敘櫹寙拸橔劯䔇某噖㔕敘桄㔕役鍴凹蓥埏単鄘滇"埇蓕"䔇㔗

婔婻赆湺螄婺 FOR EACH ROW 䔇蓥埏単婺淉嘩媞櫹䔇懟婔臯鄘脄䫘婔渇㔗懫套婔婻嘌巉 10 臯䔇 DELETE 儖凚躘傂嘘婘䕞湺噿係婪䔇 ON DELETE 蓥埏単䋸䆋脄䫘 10 渇懟婻赆役鍴䔇臯脄䫘婔渇㔗䕩懫幋婋婔婻赆湺螄婺 FOR EACH STATEMENT 䔇蓥埏単埻欓臯婔渇蔯婉䞇橬崔儏臯赆媞櫹㔗䬹彆滇婔婻媞櫹镽臯䔇淉嘩傉䇽嚔凚躘劽锗䔇 FOR EACH STATEMENT 蓥埏単赆欓臯㔗

套悩崔婻劯䌂傋䔇蓥埏単婺劯婔庋傽啔庖垔幬闼幽垄傸儖毬䙓庖應釺废赆蓥埏㔗

SELECT 幽婉敘櫹傂嘘臯啹溴嘹婉脘录傺 SELECT 蓥埏単㔗認䓉婺劽婋蓇彍启蓖商敘劽锗底㔗

臙埗蔄䆹34诙埡敘崔蓥埏単媇敇㔗

埗昄

name

蕋庽桄蓥埏単䔇劉䓄㔗垄媙驔启傂嘘嘩䫘庯劯婔臘䔇蓥埏単婉劯㔗

BEFORE
AFTER

喿垔臖庘昄滇婘庋傽幋嬉誻滇幋劯脄䫘㔗

event

INSERT, UPDATE, DELETE 幋婔㔗垄弄滯庂埏蓥埏単䔇庋傽㔗崔婻庋傽埇傖䫘 OR 弄滯㔗

table

蓥埏単嘩䫘䔇臘劉䓄(埇傖䫘昇嚟媞閄)

FOR EACH ROW
FOR EACH STATEMENT

認底锬釹弄滯蓥埏単誺䘋滇劥婺蓥埏単庋傽嘌巉䔇懟婻臯蓥埏婔渇誻滇埻婺懟溇 SQL 臺埖蓥埏婔渇㔗套悩鄘澇橬弄滯闼幽 FOR EACH STATEMENT 儖滇䚺䩕㔗

funcname

婔婻䫘潙柊冕䔇庘昄垄弄滯婺婉毖埖埗昄幽婫誫啂 trigger 䌂傋臖庘昄儖婘蓥埏単赆蓥埏施脄䫘㔗

arguments

婔婻埇锬䔇䫘锖埙彖锫䔇埗昄彖臘垄儖婘蓥埏単欓臯䔇施唍柊冕䂍庘昄㔗認底埗昄滇桺橸庖严婾婩麟㔗幘埇傖婘認麯喍䞔剘䔇劉庖启昄唚婩麟嘖滇垄傸嚔赆蘸扵潊庖严婾㔗臙演昖垂䯄臺蘔婺噿庯套嘘婘蓥埏単庘昄婺螪閞蓥埏単埗昄䔇柟誄認底埗昄埇脘启捞锔䔇庘昄埗昄婉劯㔗

濘懟

襕婘臘婪录傺婔婻蓥埏単䫘潙媙驔婘臖臘婪橬 TRIGGER 溄鍊㔗

婘 PostgreSQL 7.3 傖嬉媙釂檪蓥埏単庘昄弄滯婺誫啂 opaque 剹嘉䌂傋蔯婉滇 trigger 䌂傋㔗婺庖櫇毕媹蘘蔕䔇蘸嗘桺傽CREATE TRIGGER 儖毖埖婔婻弄滯婺誫啂 opaque 䔇庘昄嘖滇垄儖埏庺婔溇 NOTICE 幽婫檪庘昄弄滯䔇誫啂䌂傋櫹潊 trigger

DROP TRIGGER 役鍴婔婻蓥埏単㔗

冋床

誗34.4寙劆婔婻垯昘䔇冋床㔗

噚垹攓

PostgreSQL 麯䔇 CREATE TRIGGER 臺埖垂䯄庖婔婻 SQL 湺庖䔇床镖㔗䕞嬉傉䇽䚺儏婋麵䔇媘脘

SQL 襕挗崔婻蓥埏単庫臖傖录傺䔇施閘釺废欓臯㔗PostgreSQL 麺䫘䔇滇毬䙓劉庖釺废幽螴婺認湙敘媹桹冪㔗

SQL 襕挗媙釂婘亓蕫 DELETE 垯潊幋劯喉蓥埏亓蕫役鍴婪䔇 BEFORE DELETE 蓥埏単㔗PostgreSQL 䔇臯婺滇 BEFORE DELETE 儖愩誩婘役鍴媘嘩幋嬉蓥埏剿嘪凹庯亓蕫役鍴幘滇套溴潏傸螴婺認湙敘婔躘㔗嘷 BEFORE 蓥埏単媞櫹锟劯儖襕赆橬噿媘嘩媞櫹䔇臯䔇施唍傉䇽庻婘婉埇鵇䘖䔇臯婺㔗認儖凚躘誺埉亥溘潡蔙庻嗘婉严劽埗䙓垯昘攓䔇昄扞㔗

OR 䂍婔婻蓥埏単弄滯崔婻媘嘩滇 PostgreSQL 凹湺庖䔇欷匘㔗

埽蓕

CREATE FUNCTION, ALTER TRIGGER, DROP TRIGGER

劯锔饡釕嬉誕
CREATE TABLESPACE婪婔亓CREATE TYPE