21.10.2013 Views

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DDL statements<br />

Description: Creates a trigger, a block of PSQL code that is executed automatically upon certain database events<br />

or mutations to a table or view.<br />

Syntax:<br />

CREATE TRIGGER name<br />

{<br />

| <br />

| }<br />

AS<br />

[]<br />

BEGIN<br />

[]<br />

END<br />

::= FOR {tablename | viewname}<br />

[ACTIVE | INACTIVE]<br />

{BEFORE | AFTER} <br />

[POSITION number]<br />

::= [ACTIVE | INACTIVE]<br />

{BEFORE | AFTER} <br />

[POSITION number]<br />

ON {tablename | viewname}<br />

::= [ACTIVE | INACTIVE]<br />

ON db_event<br />

[POSITION number]<br />

::= mutation [OR mutation [OR mutation]]<br />

mutation ::= INSERT | UPDATE | DELETE<br />

db_event ::= CONNECT | DISCONNECT | TRANSACTION START<br />

| TRANSACTION COMMIT | TRANSACTION ROLLBACK<br />

number ::= 0..32767 (default is 0)<br />

::= See PSQL::DECLARE for the exact syntax<br />

• “Legacy” and “sql2003” relation triggers are exactly the same. The only thing that differs is the<br />

creation syntax.<br />

• Triggers with lower position numbers fire first. Position numbers need not be unique, but if two<br />

or more triggers have the same position, the firing order between them is undefined.<br />

• When defining relation triggers, each mutation type (INSERT, UPDATE or DELETE) may occur<br />

at most once in the mutation list.<br />

SQL-2003-compliant syntax for relation triggers<br />

Added in: <strong>2.1</strong><br />

Description: Since <strong>Firebird</strong> <strong>2.1</strong>, an alternative, SQL-2003-compliant syntax can be used for triggers on tables<br />

and views. Instead of specifying “FOR relationname” before the event type and the optional directives surrounding<br />

it, you can now put “ON relationname” after it, as shown in the syntax earlier in this chapter.<br />

46

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!