23.10.2012 Views

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

Openedge Data Management: SQL Reference - Product ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CREATE TRIGGER<br />

statement and does not include the optional column list, then any UPDATE on the table will<br />

activate the trigger.<br />

ON table_name<br />

Identifies the name of the table where the trigger is defined. A triggering statement that<br />

specifies table_name causes the trigger to execute. table_name cannot be the name of a<br />

view.<br />

REFERENCING OLDROW [ , NEWROW ] | NEWROW [ , OLDROW ]<br />

Provides a mechanism for <strong>SQL</strong> to pass row values as input parameters to the stored<br />

procedure implemented by java_snippet. The code in java_snippet uses the getValue<br />

method of the NEWROW and OLDROW objects to retrieve values of columns in rows affected<br />

by the trigger event and store them in procedure variables. This clause is allowed only if<br />

the trigger specifies the FOR EACH ROW clause.<br />

The meaning of the OLDROW and NEWROW arguments of the REFERENCING clause depends on<br />

whether the trigger event is INSERT, UPDATE, or DELETE. For example:<br />

• INSERT...REFERENCING NEWROW means the triggered action can access values of<br />

columns of each row inserted. <strong>SQL</strong> passes the column values specified by the INSERT<br />

statement.<br />

• INSERT...REFERENCING OLDROW is meaningless, since there are no existing values for<br />

a row being inserted. INSERT...REFERENCING OLDROW generates a syntax error.<br />

• UPDATE...REFERENCING OLDROW means the triggered action can access the values of<br />

columns, before they are changed, of each row updated. <strong>SQL</strong> passes the column<br />

values of the row as it exists in the database before the update operation.<br />

• DELETE...REFERENCING OLDROW means the triggered action can access values of<br />

columns of each row deleted. <strong>SQL</strong> passes the column values of the row as it exists<br />

in the database before the delete operation.<br />

• DELETE...REFERENCING NEWROW is meaningless, since there are no new existing values<br />

to pass for a row being deleted. DELETE...REFERENCING OLDROW generates a syntax<br />

error.<br />

• UPDATE is the only triggering statement that allows both NEWROW and OLDROW in the<br />

REFERENCING clause.<br />

• UPDATE...REFERENCING NEWROW means the triggered action can access the values of<br />

columns, after they are changed, of each row updated. <strong>SQL</strong> passes the column values<br />

specified by the UPDATE statement.<br />

• The trigger action time (BEFORE or AFTER) does not affect the meaning of the<br />

REFERENCING clause. For instance, BEFORE UPDATE...REFERENCING NEWROW still means<br />

the values of columns after they are updated will be available to the triggered action.<br />

• The REFERENCING clause generates an error if the trigger does not include the FOR<br />

EACH ROW clause.<br />

FOR EACH { ROW | STATEMENT }<br />

Controls the execution frequency of the triggered action implemented by java_snippet.<br />

25

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

Saved successfully!

Ooh no, something went wrong!