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 淉嘩)蓥埏㔗套悩蓥埏単婘庋傽幋嬉蓥埏単埇脘䘖誺嘷嬉螄嘘䔇淉嘩潡櫹埻赆某噖䔇螄嘘(埻凹 INSERT 启 UPDATE 淉嘩橬昽)㔗套悩蓥埏単婘庋傽幋劯欔橬敘櫹寙拸橔劯䔇某噖㔕敘桄㔕役鍴凹蓥埏単鄘滇"埇蓕"䔇㔗
婔婻赆湺螄婺 FOR EACH ROW 䔇蓥埏単婺淉嘩媞櫹䔇懟婔臯鄘脄䫘婔渇㔗懫套婔婻嘌巉 10 臯䔇 DELETE 儖凚躘傂嘘婘䕞湺噿係婪䔇 ON DELETE 蓥埏単䋸䆋脄䫘 10 渇懟婻赆役鍴䔇臯脄䫘婔渇㔗䕩懫幋婋婔婻赆湺螄婺 FOR EACH STATEMENT 䔇蓥埏単埻欓臯婔渇蔯婉䞇橬崔儏臯赆媞櫹㔗䬹彆滇婔婻媞櫹镽臯䔇淉嘩傉䇽嚔凚躘劽锗䔇 FOR EACH STATEMENT 蓥埏単赆欓臯㔗
套悩崔婻劯䌂傋䔇蓥埏単婺劯婔庋傽啔庖垔幬闼幽垄傸儖毬䙓庖應釺废赆蓥埏㔗
SELECT 幽婉敘櫹傂嘘臯啹溴嘹婉脘录傺 SELECT 蓥埏単㔗認䓉婺劽婋蓇彍启蓖商敘劽锗底㔗
臙埗蔄䆹34诙埡敘崔蓥埏単媇敇㔗
蕋庽桄蓥埏単䔇劉䓄㔗垄媙驔启傂嘘嘩䫘庯劯婔臘䔇蓥埏単婉劯㔗
喿垔臖庘昄滇婘庋傽幋嬉誻滇幋劯脄䫘㔗
INSERT, UPDATE, DELETE 幋婔㔗垄弄滯庂埏蓥埏単䔇庋傽㔗崔婻庋傽埇傖䫘 OR 弄滯㔗
蓥埏単嘩䫘䔇臘劉䓄(埇傖䫘昇嚟媞閄)
認底锬釹弄滯蓥埏単誺䘋滇劥婺蓥埏単庋傽嘌巉䔇懟婻臯蓥埏婔渇誻滇埻婺懟溇 SQL 臺埖蓥埏婔渇㔗套悩鄘澇橬弄滯闼幽 FOR EACH STATEMENT 儖滇䚺䩕㔗
婔婻䫘潙柊冕䔇庘昄垄弄滯婺婉毖埖埗昄幽婫誫啂 trigger 䌂傋臖庘昄儖婘蓥埏単赆蓥埏施脄䫘㔗
婔婻埇锬䔇䫘锖埙彖锫䔇埗昄彖臘垄儖婘蓥埏単欓臯䔇施唍柊冕䂍庘昄㔗認底埗昄滇桺橸庖严婾婩麟㔗幘埇傖婘認麯喍䞔剘䔇劉庖启昄唚婩麟嘖滇垄傸嚔赆蘸扵潊庖严婾㔗臙演昖垂䯄臺蘔婺噿庯套嘘婘蓥埏単庘昄婺螪閞蓥埏単埗昄䔇柟誄認底埗昄埇脘启捞锔䔇庘昄埗昄婉劯㔗
襕婘臘婪录傺婔婻蓥埏単䫘潙媙驔婘臖臘婪橬 TRIGGER 溄鍊㔗
婘 PostgreSQL 7.3 傖嬉媙釂檪蓥埏単庘昄弄滯婺誫啂 opaque 剹嘉䌂傋蔯婉滇 trigger 䌂傋㔗婺庖櫇毕媹蘘蔕䔇蘸嗘桺傽CREATE TRIGGER 儖毖埖婔婻弄滯婺誫啂 opaque 䔇庘昄嘖滇垄儖埏庺婔溇 NOTICE 幽婫檪庘昄弄滯䔇誫啂䌂傋櫹潊 trigger 㔗
䫘 DROP TRIGGER 役鍴婔婻蓥埏単㔗
PostgreSQL 麯䔇 CREATE TRIGGER 臺埖垂䯄庖婔婻 SQL 湺庖䔇床镖㔗䕞嬉傉䇽䚺儏婋麵䔇媘脘
SQL 噕螩蓥埏単婺毺垔庖枕䔇敘桄誕臯蓥埏(幘儌滇 AFTER UPDATE OF col1, col2)
SQL 噕螩嘹婺"old"启"new"臯潡蔙臘垔幬彆劉䫘庯垔幬蓥埏単䔇媘嘩(幘儌滇 CREATE TRIGGER ... ON tablename REFERENCING OLD ROW AS somename NEW ROW AS othername ...)㔗啹婺 PostgreSQL 噕螩蓥埏単誺䘋傖傂懟昄麟䔇䫘潙垔幬臺蘔誕臯幥喍欔傖螪閞昄扞䔇噖嘩滇䫘启臺蘔䕩噿䔇桹濘垂䯄䔇㔗
PostgreSQL 埻噕螩婺蓥埏䔇媘嘩欓臯䫘潙鵇噽垔幬喘䔇庘昄㔗SQL 湺庖噕螩欓臯婔底噽垄䔇变傴懫套拪 CREATE TABLE 嘩婺蓥埏単媘嘩㔗認婻鍊溵幽婉锆䂘嚔埻襕录傺婔婻欓臯認底变傴䔇䫘潙鵇垔䔇庘昄剿埇㔗
SQL 襕挗崔婻蓥埏単庫臖傖录傺䔇施閘釺废欓臯㔗PostgreSQL 麺䫘䔇滇毬䙓劉庖釺废幽螴婺認湙敘媹桹冪㔗
SQL 襕挗媙釂婘亓蕫 DELETE 垯潊幋劯喉蓥埏亓蕫役鍴婪䔇 BEFORE DELETE 蓥埏単㔗PostgreSQL 䔇臯婺滇 BEFORE DELETE 儖愩誩婘役鍴媘嘩幋嬉蓥埏剿嘪凹庯亓蕫役鍴幘滇套溴潏傸螴婺認湙敘婔躘㔗嘷 BEFORE 蓥埏単媞櫹锟劯儖襕赆橬噿媘嘩媞櫹䔇臯䔇施唍傉䇽庻婘婉埇鵇䘖䔇臯婺㔗認儖凚躘誺埉亥溘潡蔙庻嗘婉严劽埗䙓垯昘攓䔇昄扞㔗
䫘 OR 䂍婔婻蓥埏単弄滯崔婻媘嘩滇 PostgreSQL 凹湺庖䔇欷匘㔗