CREATE TRIGGER

Name

CREATE TRIGGER  --  Creates a new trigger 新しいトリガを作成します。

Synopsis

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

入力

name

The name of an existing trigger. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The name of a trigger to be created. の間違い

作成するトリガの名前です。

table

The name of a table.

テーブルの名前です。

event

One of INSERT, DELETE or UPDATE.

INSERT、DELETE または UPDATE のいずれかです。

funcname

A user-supplied function.

ユーザ定義の関数です。

出力

CREATE

This message is returned if the trigger is successfully created.

トリガが正常に作成されたときに戻るメッセージです。

説明

CREATE TRIGGER will enter a new trigger into the current data base. The trigger will be associated with the relation relname and will execute the specified function funcname.

CREATE TRIGGER は指定したデータベースに 新しいトリガを挿入します。トリガはリレーション relname と連係して、 指定された関数 funcname を実行します。

The trigger can be specified to fire either before the operation is attempted on a tuple (before constraints are checked and the INSERT, UPDATE or DELETE is attempted) or after the operation has been attempted (e.g. after constraints are checked and the INSERT, UPDATE or DELETE has completed). If the trigger fires before the event, the trigger may skip the operation for the current tuple, or change the tuple being inserted (for INSERT and UPDATE operations only). If the trigger fires after the event, all changes, including the last insertion, update, or deletion, are "visible" to the trigger.

トリガは、タプルへの操作が開始される前(制約条件のチェックと INSERT、UPDATE または DELETE が行われる前)、あるいは操作が 開始された後(制約条件がチェックされ INSERT、UPDATE または DELETE が完了した後)の前後いずれでも起動を指定することが出来ます。 イベントの前にトリガが起動すると、そのトリガは指定した タプルにたいする操作を省略することも、(INSERT と UPDATE の操作時 のみ)挿入されたタプルを変更することもできます。 イベントの後にトリガが起動すると、最終の挿入、更新あるいは 削除を含んだ全ての変更がトリガに"可視"となります。

Refer to the chapters on SPI and Triggers in the PostgreSQL Programmer's Guide for more information.

より詳しくは、 PostgreSQL プログラマガイド の SPI と トリガの章を参照して下さい。

注意事項

CREATE TRIGGER is a Postgres language extension.

CREATE TRIGGERPostgres の拡張言語です。

Only the relation owner may create a trigger on this relation.

リレーションの所有者のみが、そのリレーション上にトリガを 作成できます。

As of the current release (v6.4), STATEMENT triggers are not implemented.

現在のリリース (v6.4) 時点で、 STATEMENT トリガは 実装されていません。

Refer to DROP TRIGGER for information on how to remove triggers.

トリガを削除する方法については、 DROP TRIGGER を参照して下さい。

使用法

Check if the specified distributor code exists in the distributors table before appending or updating a row in the table films:

指定された distributor のコードが distributors テーブルに存在する かどうか、テーブル films に行を追加または更新する前にチェックします:

CREATE TRIGGER if_dist_exists
    BEFORE INSERT OR UPDATE ON films FOR EACH ROW
    EXECUTE PROCEDURE check_primary_key ('did', 'distributors', 'did');
   

Before cancelling a distributor or updating its code, remove every reference to the table films:

distributor を消去するかまたはそのコードを変更する前に、 テーブル films にたいする全ての参照を削除します。

CREATE TRIGGER if_film_exists 
    BEFORE DELETE OR UPDATE ON distributors FOR EACH ROW
    EXECUTE PROCEDURE check_foreign_key (1, 'CASCADE', 'did', 'films', 'did');
   

互換性

SQL92

There is no CREATE TRIGGER in SQL92.

SQL92 には CREATE TRIGGER は ありません。

The second example above may also be done by using a FOREIGN KEY constraint as in:

上の二番目の例は FOREIGN KEY 制約条件を使用し、以下のようにして も可能です:

CREATE TABLE distributors (
    did      DECIMAL(3),
    name     VARCHAR(40),
    CONSTRAINT if_film_exists
    FOREIGN KEY(did) REFERENCES films
    ON UPDATE CASCADE ON DELETE CASCADE  
);
    

However, foreign keys are not yet implemented (as of version 6.4) in Postgres.

とはいっても、外部キーは (6.4 時点で)未だ Postgres に実装されていません。