自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

CREATE TRIGGER 中文man頁面

系統(tǒng)
CREATE TRIGGER 創(chuàng)建一個(gè)新的觸發(fā)器。 觸發(fā)器將與指定表關(guān)聯(lián)并且將在特定事件發(fā)生時(shí)執(zhí)行聲明的函數(shù) func。

NAME

CREATE TRIGGER - 定義一個(gè)新的觸發(fā)器

SYNOPSIS

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

DESCRIPTION 描述

CREATE TRIGGER 創(chuàng)建一個(gè)新的觸發(fā)器。 觸發(fā)器將與指定表關(guān)聯(lián)并且將在特定事件發(fā)生時(shí)執(zhí)行聲明的函數(shù) func。


 觸發(fā)器可以聲明為在對(duì)記錄進(jìn)行操作之前(在檢查約束之前和 INSERT,UPDATE  或 DELETE 執(zhí)行前)或操作完成之后(在檢查約束之后和完成  INSERT, UPDATE 或 DELETE 操作)觸發(fā)。 如果觸發(fā)器在事件之前,觸發(fā)器可能略過當(dāng)前記錄的操作或改變被插入的(當(dāng)前)記錄(只對(duì) INSERT 和 UPDATE 操作有效)。 如果觸發(fā)器在事件之后,所有更改,包括***的插入, 更新或刪除對(duì)觸發(fā)器都是"可見"的。


 一個(gè) FOR EACH ROW 執(zhí)行指定操作的觸發(fā)器為操作修改的每一行都調(diào)用一次。比如,一個(gè)影響 10 行的 DELETE 將導(dǎo)致任何在目標(biāo)關(guān)系上的 ON DELETE 觸發(fā)器獨(dú)立調(diào)用 10 次, 每個(gè)被刪除的行一次。相比之下,一個(gè)為指定操作 FOR EACH STATEMENT  的觸發(fā)器只是為任何操作執(zhí)行一次,不管有多少行被修改。 (特別是,一個(gè)修改零行的操作仍然會(huì)導(dǎo)致任何合適的 FOR EACH STATEMENT 觸發(fā)器的執(zhí)行。)


 如果多個(gè)同類型的觸發(fā)器為同樣事件做了定義, 那么它們將按照字母順序被激活。

SELECT 并不更改任何行,因此你不能創(chuàng)建 SELECT 觸發(fā)器。這種場(chǎng)合下規(guī)則和視圖更合適些。


 請(qǐng)參考 Part V ``Triggers'' 獲取更多信息。  

PARAMETERS 參數(shù)

name

 賦予新觸發(fā)器的名稱。它必需和任何作用于同一表的觸發(fā)器不同。
BEFORE
AFTER

 決定該函數(shù)是在事件之前還是之后調(diào)用。
event
INSERT,DELETE 或 UPDATE 其中之一。 它聲明擊發(fā)觸發(fā)器的事件。多個(gè)事件可以用 OR 聲明。
table
觸發(fā)器作用的表名稱(可以用模式修飾)。
FOR EACH ROW
FOR EACH STATEMENT

 這些選項(xiàng)聲明觸發(fā)器過程是否為觸發(fā)器事件影響的每個(gè)行觸發(fā)一次, 還是只為每條 SQL 語句觸發(fā)一次。如果都沒有聲明, FOR EACH STATEMENT 是缺省。
func
一個(gè)用戶提供的函數(shù),它聲明為不接受參數(shù)并且返回 trigger 類型。
arguments

 一個(gè)可選的用逗號(hào)分隔的參數(shù)列表,它將在觸發(fā)器執(zhí)行的時(shí)候提供給函數(shù), 這些參數(shù)是文本字串常量。也可以在這里寫簡(jiǎn)單的名字和數(shù)值常量,但是它們會(huì)被轉(zhuǎn)換成字串。 請(qǐng)檢查實(shí)現(xiàn)語言中關(guān)于如何在觸發(fā)器函數(shù)中訪問觸發(fā)器參數(shù)的描述; 這些參數(shù)可能和普通的函數(shù)參數(shù)不同。

NOTES 注意


 要在一個(gè)表上創(chuàng)建一個(gè)觸發(fā)器,用戶必需在該表上有 TRIGGER 權(quán)限。


 在 PostgreSQL 版本 7.3 以前, 我們必須把觸發(fā)器函數(shù)聲明為返回占位類型 opaque, 而不是 trigger。為了支持裝載老的轉(zhuǎn)儲(chǔ)文件, CREATE TRIGGER 將接受一個(gè)聲明為返回 opaque 的函數(shù), 但是它將發(fā)出一條 NOTICE 并且把函數(shù)聲明的返回類型改成 trigger。


 用 DROP TRIGGER [drop_trigger(7)] 獲取如何刪除觸發(fā)器的信息。  

EXAMPLES 例子

Section 33.4 ``Triggers'' 包含一個(gè)完整的例子。  

COMPATIBILITY 兼容性

CREATE TRIGGER 里的 CREATE TRIGGER 語句實(shí)現(xiàn)了一個(gè) SQL99 標(biāo)準(zhǔn)的子集。 (SQL92 里沒有觸發(fā)器) 目前仍然缺少下面的功能∶

*
SQL99 允許觸發(fā)器為指定的字段的更新進(jìn)行觸發(fā)(也就是說,AFTER UPDATE OF col1, col2)。
*
SQL99 允許你為 "old" 和 "new" 行或者表定義別名,用于定義觸發(fā)器的動(dòng)作(也就是說, CREATE TRIGGER ... ON tablename REFERENCING OLD ROW AS somename NEW ROW AS othername ...)。因?yàn)?PostgreSQL 允許觸發(fā)器過程以任意數(shù)量的用戶定義語言進(jìn)行書寫,所以訪問數(shù)據(jù)的工作是用和語言相關(guān)的方法實(shí)現(xiàn)的。
*
PostgreSQL 只允許為觸發(fā)的動(dòng)作執(zhí)行存儲(chǔ)的過程。SQL99 允許執(zhí)行一些其他的 SQL 命令, 比如那 CREATE TABLE 作為觸發(fā)器動(dòng)作。 這個(gè)限止并不難繞開,只要?jiǎng)?chuàng)建一個(gè)執(zhí)行這些命令的存儲(chǔ)過程即可。

SQL99 要求多個(gè)觸發(fā)器應(yīng)該以創(chuàng)建的時(shí)間順序執(zhí)行。 PostgreSQL 采用的是按照名字順序, 我們認(rèn)為這樣更加方便。


 用 OR 給一個(gè)觸發(fā)器聲明多個(gè)動(dòng)作是 PostgreSQL  對(duì)標(biāo)準(zhǔn)的擴(kuò)展。  

SEE ALSO 參見

CREATE FUNCTION [create_function(7)], ALTER TRIGGER [alter_trigger(l)], DROP TRIGGER [drop_trigger(l)]  

#p#

NAME

CREATE TRIGGER - define a new trigger

SYNOPSIS

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

DESCRIPTION

CREATE TRIGGER creates a new trigger. The trigger will be associated with the specified table and will execute the specified function func when certain events occur.

The trigger can be specified to fire either before before the operation is attempted on a row (before constraints are checked and the INSERT, UPDATE, or DELETE is attempted) or after the operation has completed (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 row, or change the row 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.

A trigger that is marked FOR EACH ROW is called once for every row that the operation modifies. For example, a DELETE that affects 10 rows will cause any ON DELETE triggers on the target relation to be called 10 separate times, once for each deleted row. In contrast, a trigger that is marked FOR EACH STATEMENT only executes once for any given operation, regardless of how many rows it modifies (in particular, an operation that modifies zero rows will still result in the execution of any applicable FOR EACH STATEMENT triggers).

If multiple triggers of the same kind are defined for the same event, they will be fired in alphabetical order by name.

SELECT does not modify any rows so you can not create SELECT triggers. Rules and views are more appropriate in such cases.

Refer to the chapter called ``Triggers'' in the documentation for more information about triggers.  

PARAMETERS

name
The name to give the new trigger. This must be distinct from the name of any other trigger for the same table.
BEFORE
AFTER
Determines whether the function is called before or after the event.
event
One of INSERT, UPDATE, or DELETE; this specifies the event that will fire the trigger. Multiple events can be specified using OR.
table
The name (optionally schema-qualified) of the table the trigger is for.
FOR EACH ROW
FOR EACH STATEMENT
This specifies whether the trigger procedure should be fired once for every row affected by the trigger event, or just once per SQL statement. If neither is specified, FOR EACH STATEMENT is the default.
func
A user-supplied function that is declared as taking no arguments and returning type trigger, which is executed when the trigger fires.
arguments
An optional comma-separated list of arguments to be provided to the function when the trigger is executed. The arguments are literal string constants. Simple names and numeric constants may be written here, too, but they will all be converted to strings. Please check the description of the implementation language of the trigger function about how the trigger arguments are accessible within the function; it may be different from normal function arguments.

NOTES

To create a trigger on a table, the user must have the TRIGGER privilege on the table.

In PostgreSQL versions before 7.3, it was necessary to declare trigger functions as returning the placeholder type opaque, rather than trigger. To support loading of old dump files, CREATE TRIGGER will accept a function declared as returning opaque, but it will issue a notice and change the function's declared return type to trigger.

Use DROP TRIGGER [drop_trigger(7)] to remove a trigger.  

EXAMPLES

The chapter called ``Triggers'' in the documentation contains a complete example.  

COMPATIBILITY

The CREATE TRIGGER statement in PostgreSQL implements a subset of the SQL99 standard. (There are no provisions for triggers in SQL92.) The following functionality is missing:

*
SQL99 allows triggers to fire on updates to specific columns (e.g., AFTER UPDATE OF col1, col2).
*
SQL99 allows you to define aliases for the ``old'' and ``new'' rows or tables for use in the definition of the triggered action (e.g., CREATE TRIGGER ... ON tablename REFERENCING OLD ROW AS somename NEW ROW AS othername ...). Since PostgreSQL allows trigger procedures to be written in any number of user-defined languages, access to the data is handled in a language-specific way.
*
PostgreSQL only allows the execution of a user-defined function for the triggered action. SQL99 allows the execution of a number of other SQL commands, such as CREATE TABLE as triggered action. This limitation is not hard to work around by creating a user-defined function that executes the desired commands.

SQL99 specifies that multiple triggers should be fired in time-of-creation order. PostgreSQL uses name order, which was judged more convenient to work with.

The ability to specify multiple actions for a single trigger using OR is a PostgreSQL extension of the SQL standard.  

SEE ALSO

CREATE FUNCTION [create_function(7)], ALTER TRIGGER [alter_trigger(l)], DROP TRIGGER [drop_trigger(l)]

責(zé)任編輯:韓亞珊 來源: CMPP.net
相關(guān)推薦

2011-08-24 10:53:20

CREATE CONS中文man

2011-08-24 09:48:46

alter_trigg中文man

2011-08-24 14:52:31

drop_trigge中文man

2011-08-24 13:23:10

CREATE SCHE中文man

2011-08-24 13:26:19

CREATE SEQU中文man

2011-08-24 11:18:53

CREATE LANG中文man

2011-08-24 11:23:20

CREATE OPER中文man

2011-08-24 11:31:47

CREATE RULE中文man

2011-08-24 13:39:44

CREATE TYPE中文man

2011-08-24 10:59:19

CREATE DATA中文man

2011-08-24 11:02:11

CREATE DOMA中文man

2011-08-24 11:05:36

CREATE FUNC中文man

2011-08-24 11:10:17

CREATE GROU中文man

2011-08-24 13:43:09

CREATE USER中文man

2011-08-24 13:46:39

CREATE VIEW中文man

2011-08-24 13:29:20

CREATE TABL中文man

2011-08-24 10:56:32

CREATE CONV中文man

2011-08-24 10:46:36

CREATE AGGR中文man

2011-08-24 11:15:24

CREATE INDE中文man

2011-08-24 13:32:56

CREATE TABL中文man
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)