Informix Triggers PDF
Informix Triggers PDF
Version 5.x
December 2001
Part No. 000-7230A
Note:
Before using this information and the product it supports, read the information in the appendix
entitled “Notices.”
This document contains proprietary information of IBM. It is provided under a license agreement and is
protected by copyright law. The information contained in this publication does not include any product
warranties, and any statements provided in this manual should not be interpreted as such.
When you send information to IBM, you grant IBM a nonexclusive right to use or distribute the information
in any way it believes appropriate without incurring any obligation to you.
© Copyright International Business Machines Corporation 1996, 2001. All rights reserved.
US Government User Restricted Rights—Use, duplication or disclosure restricted by GSA ADP Schedule
Contract with IBM Corp.
ii Using Triggers
Preface
Using Triggers is a complete guide to using triggers in the Informix implemen-
tation of Structured Query Language (SQL).
This user manual assumes that you have database management experience
and are familiar with relational database concepts. It also assumes that you
have knowledge of SQL and stored procedures. The Informix implementation
of SQL is described in detail in a separate set of manuals called The Informix
Guide to SQL: Tutorial and The Informix Guide to SQL: Reference. The Informix
Guide to SQL: Reference also describes stored procedures and the Stored
Procedure Language (SPL).
Using Triggers is both a user guide and a reference manual. The first chapter is
an introduction to triggers. It tells you how to create and use triggers. The sec-
ond chapter is a reference chapter. It describes both the syntax of the SQL state-
ments for triggers and what happens when they execute.
Summary of Chapters
The Using Triggers user manual includes the following chapters:
• This Preface provides general information about the user manual and lists
additional reference materials that help you understand concepts related
to triggers.
• The Introduction describes how triggers fit into the Informix database
server products, INFORMIX-OnLine and INFORMIX-SE. It explains how to
use this user manual, describes other Informix product documentation,
introduces the demonstration database from which the product examples
are drawn, and describes the Informix Messages and Corrections product.
• Chapter 1, “An Introduction to Triggers,” provides an introduction to trig-
gers. It explains how to create triggers and describes some of the uses for
Related Reading
Related Reading
If you have prior experience with database management and are familiar
with relational database concepts, but you would like more technical infor-
mation, consider consulting the following texts by C. J. Date:
• An Introduction to Database Systems, Volume I (Addison-Wesley
Publishing, 1990)
• An Introduction to Database Systems, Volume II (Addison-Wesley
Publishing, 1983)
This guide assumes you are familiar with your computer operating system.
If you have limited UNIX system experience, you may want to look at your
operating system manual or a good introductory text before starting to learn
about triggers.
Some suggested texts about UNIX systems follow:
• A Practical Guide to the UNIX System by M. Sobell (Benjamin/Cummings
Publishing, 1984)
• A Practical Guide to UNIX System V by M. Sobell (Benjamin/Cummings
Publishing, 1985)
• UNIX for People by Birns, Brown, and Muster (Prentice-Hall, 1985)
iv Preface
Table of
Contents
Table of Contents
Introduction
The Triggers Feature and Informix Products 3
Other Useful Documentation 4
How to Use This Manual 4
Typographical Conventions 5
Syntax Conventions 5
Example Code Conventions 9
Useful On-Line Files 10
ASCII and PostScript Error Message Files 10
Using the ASCII Error Message File 11
Using the PostScript Error Message Files 13
The Demonstration Database 13
Creating the Demonstration Database on
INFORMIX-OnLine 14
Creating the Demonstration Database on
INFORMIX-SE 15
Compliance with Industry Standards 16
Appendix A Notices
Error Messages
Index
vi Table of Contents
Introduction
Introduction
The Triggers Feature and Informix Products 3
Other Useful Documentation 4
How to Use This Manual 4
Typographical Conventions 5
Syntax Conventions 5
Example Code Conventions 9
Useful On-Line Files 10
ASCII and PostScript Error Message Files 10
Using the ASCII Error Message File 11
The finderr Script 11
The rofferr Script 12
Using the PostScript Error Message Files 13
The Demonstration Database 13
Creating the Demonstration Database on
INFORMIX-OnLine 14
Creating the Demonstration Database on
INFORMIX-SE 15
Compliance with Industry Standards 16
2 Introduction
An SQL trigger is a mechanism that automatically sets off a specified set of
SQL statements when a triggering event occurs on a table. It enables you to
automate logically related changes to the database.
Triggers are stored in the database and, therefore, can reduce the amount of
code that is required in programs that interact with the database. Two SQL
statements, CREATE TRIGGER and DROP TRIGGER, allow you to create trig-
gers on and drop triggers from tables, respectively. Two system catalog
tables, systriggers and systrigbody, store information about the triggers in
the database.
Introduction 3
Other Useful Documentation
4 Introduction
How to Use This Manual
Typographical Conventions
The Using Triggers user manual uses a standard set of conventions to intro-
duce new terms, illustrate screen displays, describe command syntax, and so
forth. The following typographical conventions are used throughout the
manual:
italics When new terms are introduced, they are printed in italics.
boldface Database names, table names, column names, file names,
utilities, and other similar terms are printed in boldface.
computer Information that your Informix product displays and infor-
mation that you enter are printed in a computer typeface.
KEYWORD All keywords appear in uppercase letters.
Additionally, when you are instructed to “enter” or “execute” text,
immediately press RETURN after the entry. When you are instructed to
“type” the text, no RETURN is required.
Syntax Conventions
Syntax diagrams describe the format of SQL statements or commands,
including alternative forms of a statement, required and optional parts of the
statement, and so forth. Syntax diagrams have their own conventions, which
are defined in detail and illustrated in this section. SQL statements are listed
in their entirety in Chapter 7 of The Informix Guide to SQL: Reference, although
some statements may appear in other manuals.
Each syntax diagram displays the sequences of required and optional
elements that are valid in a statement. Briefly:
• All keywords are shown in uppercase letters for ease of identification,
even though you need not enter them that way.
• Words for which you must supply values are in italics.
A diagram begins at the upper left with a keyword. It ends at the upper right
with a vertical line. Between these points you can trace any path that does not
stop or back up. Each path describes a valid form of the statement.
Introduction 5
How to Use This Manual
6 Introduction
How to Use This Manual
E/CO
E/C
E/C This path is valid only for INFORMIX-ESQL/COBOL.
E/C
E/F
E/C This path is valid only for INFORMIX-ESQL/
FORTRAN.
DB
E/C This path is valid only for DB-Access.
STAR
SPL This path is valid only if you are using Informix
Stored Procedure Language (SPL).
+
+ This path is an Informix extension to ANSI standard
SQL. If you initiate Informix extension checking and
include this syntax branch, you receive a warning. If
you set the DBANSIWARN environment variable,
you receive the warnings at run time. To receive the
warnings at compile time, compile with the -ansi
flag.
ALL A shaded option is the default. Even if you do not explicitly
type the option, it will be in effect unless you choose another
option.
Syntax enclosed in a pair of arrows indicates that this is
a subdiagram.
The vertical line is a terminator and indicates that the
statement is complete.
IN
A branch below the main line indicates an optional path.
NOT
,
A loop indicates a path that can be repeated.
variable
In Chapter 7 of The Informix Guide to SQL: Reference, icons that appear in the
left margin indicate that the accompanying shaded text is valid only for some
products or under certain conditions. In addition to the icons described in the
preceding list, you may encounter the following icons in the left margin:
ANSI This icon indicates that the functionality described in the
shaded text is valid only if your database is ANSI-compliant.
X/O This icon indicates that the functionality described in the
shaded text conforms to X/Open standards for dynamic SQL.
This functionality is available when you compile your
embedded-language application with the -xopen flag.
Introduction 7
How to Use This Manual
Figure 1 shows the elements of a syntax diagram for the CREATE DATABASE
statement.
Reference Boxes
Terminator
Signals
CREATE DATABASE database name
Punctuation
SE Log Clause
MODE ANSI
Subdiagrams
OL Log Clause
WITH LOG
BUFFERED
To construct a statement using this diagram, start at the top left with the
keywords CREATE DATABASE. Then follow the diagram to the right, pro-
ceeding through the options that you want. The diagram conveys the
following information:
1. You must type the words CREATE DATABASE.
2. You must supply a database name.
3. You can stop, taking the direct route to the terminator, or you can take one
or more of the optional paths.
4. If desired, you can designate a dbspace by typing the word IN and a
dbspace name.
8 Introduction
How to Use This Manual
5. If desired, you can specify logging. Here, you are constrained by the
database server with which you are working.
• If you are using INFORMIX-OnLine, go to the subdiagram named OL
Log Clause. Follow the subdiagram by typing the keyword WITH, then
choosing and typing either LOG, BUFFERED LOG, or LOG MODE ANSI.
Then, follow the arrow back to the main diagram.
• If you are using INFORMIX-SE, go to the subdiagram named SE Log
Clause. Follow the subdiagram by typing the keywords WITH LOG IN,
typing a double quote, supplying a pathname, and closing the quotes.
You can then choose the MODE ANSI option below the line or continue
to follow the line across.
6. Once you are back at the main diagram, you come to the terminator. Your
CREATE DATABASE statement is complete.
DATABASE stores5
.
.
.
DELETE FROM customer
WHERE customer_num = 121
.
.
.
COMMIT WORK
CLOSE DATABASE
Introduction 9
Useful On-Line Files
If you are using DB-Access, add semicolons at the end of each statement. If
you are using INFORMIX-ESQL/C, add EXEC SQL or a dollar sign ($) at the
beginning of each line and end each line with a semicolon. For detailed direc-
tions on using SQL statements for a specific application development tool, see
the manual for your product.
Also note that ellipses in the example indicate that more code would be
added in a full application, but it is not necessary to show it to describe the
concept being discussed.
Please examine these files because they contain vital information about
application and performance issues.
A number of Informix products also provide on-line Help files that walk you
through each menu option. To invoke the Help feature in DB-Access, for
example, simply press CTRL-W wherever you are in DB-Access.
10 Introduction
ASCII and PostScript Error Message Files
finderr msg_num
-
+
Introduction 11
ASCII and PostScript Error Message Files
For example, to display the -359 error message, you can enter the following
command:
finderr -359
- end_msg
+ -
start_msg is the number of the first error message to format. This error
message number is required.
end_msg is the number of the last error message to format. This error
message number is optional. If you omit end_msg, only
start_msg is formatted.
The following example formats error message -359. It pipes the formatted
error message into nroff and sends the output of nroff to the default printer:
12 Introduction
The Demonstration Database
The following example formats and then prints all the error messages
between -1300 and -4999:
Introduction 13
The Demonstration Database
If you install your Informix database server product according to the instal-
lation instructions, the files that make up the demonstration database are
protected so that you cannot make any changes to the original database.
You can run the dbaccessdemo5 script again whenever you want to work
with a fresh demonstration database. The script prompts you when the cre-
ation of the database is complete, and asks if you would like to copy the sam-
ple command files to the current directory. Answer “N” to the prompt if you
have made changes to the sample files and do not want them replaced with
the original versions. Answer “Y” to the prompt if you want to copy over the
sample command files.
4. Create the demonstration database and copy over the sample command
files by entering
dbaccessdemo5 dbname
The data for the database is put into the root dbspace.
To give someone else the SQL privileges to access the data, use the GRANT
and REVOKE statements. The GRANT and REVOKE statements are described
in Chapter 7 of The Informix Guide to SQL: Reference.
To use the command files that have been copied to your directory, you must
have UNIX read and execute permissions for each directory in the pathname
of the directory from which you ran the dbaccessdemo5 script. To give some-
one else the permissions to access the command files in your directory, use
the UNIX chmod command.
14 Introduction
The Demonstration Database
4. Create the demonstration database and copy over the sample command
files by entering
dbaccessdemo5 dbname
Introduction 15
Compliance with Industry Standards
16 Introduction
Chapter
1
An Introduction to
Triggers
Chapter Overview 3
An Overview of Triggers 3
Creating a Trigger 4
Components of the CREATE TRIGGER Statement 4
Trigger Name 4
Trigger Event 4
REFERENCING Clause 5
Action Clause 5
Creating a Trigger Using DB-Access 6
Adding Comments in DB-Access 6
Creating a Trigger Using ESQL/C and
ESQL/COBOL 7
Looking up a Trigger in the System Catalog 8
Using Triggers 10
Creating an Audit Trail 10
Implementing Business Rules 12
Deriving Additional Data 14
Enforcing Referential Integrity 16
Tracing Triggered Actions 17
Generating Error Messages 18
1-2 An Introduction to Triggers
Chapter Overview
This chapter is an introduction to creating and using SQL triggers in Informix
databases. It tells you what a trigger is and how to create one using either the
DB-Access utility or one of the Informix embedded-language products. The
chapter provides several examples that illustrate some of the uses for trig-
gers, the use of stored procedures as triggered actions, and the ability to cas-
cade triggers. This chapter also shows you how to debug triggers and how to
generate error messages inside triggered actions.
An Overview of Triggers
An SQL trigger is a mechanism that automatically sets off a specified set of
SQL statements when a triggering event occurs on a table. For example, when
you insert a row into a table of order items, you might want to calculate the
total price of all items that the customer has ordered to see if the total price
exceeds the customer’s credit limit. Or when you delete an item from the
table of items, you might want to delete the corresponding order from the
table of orders if all the items for it have been deleted. Triggers enable you to
automate these types of procedures.
Basically, a trigger consists of a trigger event and a resulting triggered action.
The trigger event can be an INSERT or DELETE statement, or it can be an
UPDATE statement that updates one or more columns that you specify as trig-
gering columns in a table. The triggered action is the set of SQL statements
that are executed when the trigger event occurs. The triggered action can con-
sist of INSERT, DELETE, UPDATE, and EXECUTE PROCEDURE statements. See
The Informix Guide to SQL: Reference for more information about these SQL
statements.
A trigger is stored as an object in the database. Any user who has the required
privilege can use it. As a result, triggers can reduce the amount of code that
is required in applications that access the database. Triggers can also prevent
redundant code that would otherwise be required when multiple programs
perform the same operations on the database.
Among other uses, you can use triggers to create an audit trail, implement
business rules, derive additional data, and enforce referential integrity. See
“Using Triggers” on page 1-10 for examples of these uses.
Creating a Trigger
You use the CREATE TRIGGER statement to create a trigger on a table. You can
create a trigger using either DB-Access, INFORMIX-ESQL/C, or INFOR-
MIX-ESQL/COBOL.
Trigger Name
The first part of the CREATE TRIGGER statement assigns a name to the trigger.
The name of the trigger follows the keywords CREATE TRIGGER. In Figure
1-1, the name of the trigger is items_ins.
Trigger Event
The second part of the CREATE TRIGGER statement specifies the trigger event.
In Figure 1-1, the trigger event is an INSERT on the items table. See The Infor-
mix Guide to SQL: Reference for a complete description of the tables in the
stores5 demonstration database.
REFERENCING Clause
The third part of the CREATE TRIGGER statement is the optional REFERENC-
ING clause. You can only use the REFERENCING clause with an action clause
that begins with the keywords FOR EACH ROW, as in Figure 1-1. (See the next
section “Action Clause” for the meaning of the keywords FOR EACH ROW.)
The REFERENCING clause lets you define two prefixes that you can use in the
action clause with a column name from the triggering table. One prefix refers
to the value of a column before the triggering statement takes effect; the other
prefix refers to the value of a column after the triggering statement takes
effect. If the triggering statement is an UPDATE, for example, you might want
to refer in the action clause to either the old or new value of the column in the
current row. You can refer to either value by defining a prefix for it.
In Figure 1-1, the REFERENCING clause uses the keyword NEW to define a
new prefix name called post_ins. A new prefix name refers to column values
after the triggering statement takes effect. In the action clause, post_ins pre-
cedes the column name manu_code to refer to the value of that column after
the triggering insert is complete. To define a prefix name that refers to column
values before the triggering statement takes effect, precede the prefix name
in the REFERENCING clause with the keyword OLD.
In the remainder of this user manual, the old and new prefix names are called
correlation names. See “Using Correlation Names in Triggered Actions” on
page 2-24 for more information on the proper use of these names.
Action Clause
The fourth, and last, part of the CREATE TRIGGER statement is the action
clause. The action clause consists of the following two parts:
• Keywords that specify when the action occurs, relative to the triggering
statement
• Triggered action lists that contain the SQL statements to be executed.
In Figure 1-1, the keywords FOR EACH ROW specify that the triggered action
that follows occurs once for each row that the triggering statement inserts. In
this case, the triggered action list consists of a single EXECUTE PROCEDURE
statement that calls the stored procedure items_pct.
You can also define triggered action lists that are preceded by the keywords
BEFORE and AFTER. The keyword BEFORE tells the database server to execute
the statements in the triggered action list before it executes the triggering
statement. The keyword AFTER tells the database server to execute the state-
ments in the triggered action list after the triggering statement is complete.
BEFORE and AFTER triggered actions execute only once, whereas FOR EACH
ROW triggered actions execute for each row that the triggering statement
inserts, deletes, or updates.
In Figure 1-1, for each row that the database server inserts into the items
table, it subsequently executes the items_pct stored procedure.
SQL: New Run Modify Use-editor Output Choose Save Info Drop Exit
Run the current SQL statements.
#include <stdio.h>
main()
{
.
.
.
EXEC SQL DATABASE stores5;
EXEC SQL CREATE TRIGGER items_ins INSERT ON items
REFERENCING NEW AS post_ins
FOR EACH ROW(EXECUTE items_pct (post_ins.manu_code));
.
.
.
PROCEDURE DIVISION.
MAIN.
.
.
.
EXEC SQL DATABASE STORES5 END-EXEC. --open stores5 database
EXEC SQL CREATE TRIGGER items_ins
INSERT ON items
REFERENCING NEW AS post_ins
FOR EACH ROW(EXECUTE items_pct (post_ins.manu_code)) END-EXEC.
.
.
.
Note: When you use an embedded-language product to create a trigger within a pro-
gram, the comments within the CREATE TRIGGER statement are not preserved. The
embedded-language preprocessor strips the comments from the program before the
database server stores the definition in the systrigbody table.
subquery on systriggers to obtain the value of trigid for this trigger. For more
information on the systrigbody and systriggers system catalog tables, see
“System Catalog Tables for Triggers” on page 2-3.
The DB-Access screen shown in Figure 1-6 displays the result of this query.
The header information for a trigger consists of the trigger name, the trigger-
ing statement, and the REFERENCING clause.
SQL: New Run Modify Use-editor Output Choose Save Info Drop Exit
Run the current SQL statements.
seqno 0
data CREATE TRIGGER "royr".upqty_i UPDATE OF quantity ON "royr".items REFEREN
CING OLD AS pre_upd NEW AS post_upd;
1 row(s) retrieved.
Figure 1-6 Result of a query on the systrigbody table for a trigger header
Using Triggers
Triggers let you automate changes to the database. With triggers, an insert,
delete, or update on a table can set off additional changes to the database to
enforce various rules or practices. Triggers can enforce accounting rules,
automate departmental practices, perform calculations, maintain the integ-
rity of the database, and so on. To illustrate some uses for triggers, this section
provides examples of the following applications:
• Creating an audit trail
• Implementing business rules
• Deriving additional data
• Enforcing referential integrity
An update of the quantity column in the items table activates the upqty_i
trigger. The action clause specifies FOR EACH ROW, which means that the
triggered action occurs once for each row that the triggering statement
updates in the items table. After each row is updated, the triggered action
inserts a row into the log_record table, which stores the values for the
item_num and order_num columns from the updated row. It also stores the
user’s name, the time of the update, and the old and new values for quantity.
An UPDATE statement like the one in the following example activates
upqty_i.
When this UPDATE statement triggers upqty_i , the triggered INSERT state-
ment inserts four rows in the log_record table, as shown in Figure 1-8.
Figure 1-8 Rows inserted to the log_record table by the upqty_i trigger
SQL: New Run Modify Use-editor Output Choose Save Info Drop Exit
Modify the current SQL statements using the SQL editor.
When you use a stored procedure as a triggered action in a FOR EACH ROW
action clause, you can use the INTO clause of the EXECUTE PROCEDURE state-
ment to update nontriggering columns in the current row of the triggering
table with values returned by the procedure. Outside of a triggered action,
the syntax of the EXECUTE PROCEDURE statement restricts you to using only
embedded language host variables in the INTO clause. Inside a triggered
action, however, you can name columns from the triggering table in the INTO
clause. In a triggered action, use of the INTO clause in the EXECUTE PROCE-
DURE statement implies that the columns named are updated with values
that the procedure returns. In the example, the stored procedure calc_totpr
returns n_total, which is updated into the total_price column of the current
row in the items table.
Prior to an update that triggers upd_totpr, these four rows appear as shown
in Figure 1-12:
An UPDATE statement that doubles the value of quantity for these four rows
also triggers upd_totpr, which produces a corresponding increase in the
total_price column. Figure 1-13 shows the result of both the update and the
trigger for these same four rows.
straint, the database server returns the error before the triggered action exe-
cutes. See “Constraint Checking” on page 2-30 for more information on how
the database server checks constraints when it executes a trigger.
Notice in Figure 1-14 that the two triggers cascade, meaning that the action
of one trigger sets off another one. INFORMIX-OnLine and INFORMIX-SE
both allow triggers to cascade up to a maximum of 61 triggers in a series,
including the initial trigger. In Figure 1-14, the delete on the orders table in
the first trigger, del_cust, sets off the second trigger, del_items. See “Cascad-
ing Triggers” on page 2-29 for more information on cascading triggers.
Figure 1-16 shows the trace output from the items_pct procedure to the file
/usr/mydir/trig.trace. The trace output reveals the values of procedure vari-
ables, procedure arguments, return values, and error codes.
You can apply error number -745 to any trigger failure that is not an SQL error.
The fixed message for this error is as follows:
-745 Trigger execution has failed.
You can generate this message by using the RAISE EXCEPTION statement in
SPL. The following example generates error -745 if new_qty is greater than
old_qty multiplied by 1.50.
If you are using the DB-Access utility, the text of the message for error -745
displays on the bottom of the screen, as seen in Figure 1-17.
SQL: New Run Modify Use-editor Output Choose Save Info Drop Exit
Modify the current SQL statements using the SQL editor.
SQL: New Run Modify Use-editor Output Choose Save Info Drop Exit
Modify the current SQL statements using the SQL editor.
A Reference for
Triggers
2
Chapter Overview 3
System Catalog Tables for Triggers 3
SYSTRIGGERS 4
SYSTRIGBODY 5
SQL Statements for Triggers 6
CREATE TRIGGER 7
Purpose 7
Syntax 7
Usage 8
The Trigger Event 8
Impact of Triggers 10
Trigger Name 11
UPDATE Clause 12
Defining Multiple Update Triggers 12
When an UPDATE Statement Activates
Multiple Triggers 13
Action Clause 14
BEFORE Actions 14
FOR EACH ROW Actions 14
AFTER Actions 15
Actions of Multiple Triggers 15
Guaranteeing Row-Order Independence 15
INSERT REFERENCING Clause 17
DELETE REFERENCING Clause 18
UPDATE REFERENCING Clause 19
Action Clause Subset 20
Triggered Action 21
The WHEN Condition 21
The Action Statements 22
Using Correlation Names in Triggered Actions 24
When to Use Correlation Names 24
Qualified Versus Unqualified Value 25
Rules for Stored Procedures 27
Privileges to Execute Triggered Actions 28
Cascading Triggers 29
Constraint Checking 30
Preventing Triggers from Overriding Each Other 31
The Client/Server Environment 32
Logging and Recovery 33
DROP TRIGGER 35
Purpose 35
Syntax 35
Usage 35
Triggers and Other SQL Statements 36
SYSTRIGGERS
The systriggers system catalog table contains miscellaneous information
about the trigger, including the trigger event and the correlated reference
specification. The systriggers system catalog table has the following
columns:
Column
Name Type Explanation
trigid SERIAL trigger ID
trigname CHAR(18) trigger name
owner CHAR(8) owner of trigger
tabid INT ID of triggering table
event CHAR triggering event:
I insert trigger
U update trigger
D delete trigger
old CHAR(18) name of value before update
new CHAR(18) name of value after update
mode CHAR (reserved for future use)
A composite index for the trigname and owner columns allows only unique
values. The trigid column is indexed and must contain unique values. An
index for the tabid column allows duplicate values.
If REFERENCING is specified in the trigger, the old correlation name is stored
in the field old and the new correlation name is stored in the field new. See
“INSERT REFERENCING Clause” on page 2-17, “DELETE REFERENCING
Clause” on page 2-18, and “UPDATE REFERENCING Clause” on page 2-19
for more information on the correlated-reference specification.
SYSTRIGBODY
The systrigbody system catalog table contains the linearized code for the
trigger and the English text for both the trigger definition and the triggered
actions. Linearized code is binary data and code that are represented in ASCII
format.
Warning: The database server uses the linearized code that is stored in systrigbody.
You must not alter the content of rows that contain linearized code.
The systrigbody system catalog table has the following columns:
Column
Name Type Explanation
trigid INT trigger ID
datakey CHAR type of data:
D English text for the header, trigger
definition
A English text for the body, triggered
actions
H linearized code for the header
S linearized code for the symbol table
B linearized code for the body
seqno INT sequence number
data CHAR(256) English text or linearized code
A composite index for the trigid, datakey, and seqno columns allows only
unique values.
CREATE TRIGGER
Purpose
Use the CREATE TRIGGER statement to create a new trigger.
Syntax
DB
E/C Trigger
CREATE TRIGGER Name
E/CO p. 2-11
+
Table Action
INSERT ON Name Clause
see SQLR p. 2-14
INSERT Action
REFERENCING Clause
Clause (Subset)
p. 2-17 p. 2-20
Table Action
DELETE ON Name Clause
see SQLR 2-14
DELETE Action
REFERENCING Clause
Clause (Subset)
p. 2-18 p. 2-20
UPDATE Action
REFERENCING Clause
Clause (Subset)
p. 2-19 p. 2-20
Usage
You must be either the owner of the table or the database administrator (DBA)
to create a trigger on a table.
You can define a trigger with a standalone CREATE TRIGGER statement, or
you can define it as part of a schema by placing the CREATE TRIGGER state-
ment inside a CREATE SCHEMA statement.
You can only create a trigger on a table in the current database. You cannot
create a trigger on a temporary table, a view, or a system catalog table.
You cannot create a trigger inside a stored procedure if the procedure is called
inside a data manipulation statement. For example, you cannot create a trig-
ger inside the stored procedure sp_items in the following INSERT statement:
See Chapter 7 of The Informix Guide to SQL: Reference for a list of data manip-
ulation statements.
For each table, you can define only one trigger that is activated by an INSERT
statement and only one trigger that is activated by a DELETE statement. For
each table, you can define multiple triggers that are activated by UPDATE
statements. See “UPDATE Clause” on page 2-12 for more information about
multiple triggers on the same table.
-- Trigger on stores5@dbserver1:newtab
Impact of Triggers
The INSERT, DELETE, and UPDATE statements that initiate triggers might
appear to execute slowly because they activate additional SQL statements,
and the user might not know that other actions are occurring.
The execution time for a triggering data manipulation statement depends on
the complexity of the triggered action and whether it, in turn, initiates other
triggers. Obviously, the elapsed time for the triggering data manipulation
statement increases as the number of cascading triggers increases. See “Cas-
cading Triggers” on page 2-29 for more information on triggers initiating
other triggers.
Trigger Name
Trigger
Name
Identifier
see SQLR
owner.
UPDATE Clause
UPDATE
Clause
UPDATE
,
OF column name
column name is the name of a column that will activate the trigger.
If the trigger event is an UPDATE statement, the trigger executes if any of the
columns in the triggering column list are updated.
If you specify one or more triggering column names, the column names must
belong to the table on which you create the trigger. If you do not specify a list
of triggering columns, the default list consists of all the columns in the table
on which you create the trigger.
If the triggering UPDATE statement updates more than one of the triggering
columns in a trigger, the trigger only executes once.
then trig1 for columns a and c executes first, and trig2 for columns b and d
executes next. In this case, the smallest column number in the two triggers is
column 1 (a) and the next is column 2 (b).
Action Clause
Action
Clause
Triggered
BEFORE Action
p. 2-21 Triggered Triggered
FOR EACH AFTER
Action Action
ROW p. 2-21 p. 2-21
The action clause defines the triggered actions and specifies when they occur.
You must define at least one triggered action, using the keywords BEFORE,
FOR EACH ROW, or AFTER to indicate when the action is to occur, relative to
the triggering statement. You can define triggered actions for all three options
on a single trigger, but you must order them in sequence: BEFORE, FOR EACH
ROW, and then AFTER. You cannot follow a FOR EACH ROW triggered action
list with a BEFORE triggered action list. If the first triggered action list is FOR
EACH ROW, an AFTER action list is the only option that can follow it. See
“Action Clause Subset” on page 2-20 for more information on the action
clause when a REFERENCING clause is present.
BEFORE Actions
The BEFORE triggered action executes once before the triggering statement
executes. If the triggering statement does not process any rows, the BEFORE
triggered actions still execute because it is not yet known whether any row is
affected.
If the triggering statement does not insert, delete, or update any rows, the
FOR EACH ROW triggered actions do not execute.
AFTER Actions
An AFTER triggered action executes once after the action of the triggering
statement is complete. If the triggering statement does not process any rows,
the AFTER triggered action still executes.
Next, assume that you define trig1 on columns a and c, and trig2 on columns
b and d. If both triggers have triggered actions that are executed BEFORE, FOR
EACH ROW, and AFTER, then the triggered actions are executed in the follow-
ing sequence:
1. BEFORE action list for trigger (a, c)
2. BEFORE action list for trigger (b, d)
3. FOR EACH ROW action list for trigger (a, c)
4. FOR EACH ROW action list for trigger (b, d)
5. AFTER action list for trigger (a, c)
6. AFTER action list for trigger (b, d)
The database server treats the triggers as a single trigger, and the triggered
action is the merged action list. All the rules governing a triggered action
apply to the merged list as one list, and no distinction is made between the
two original triggers.
SELECT statement in the FOR EACH ROW section varies as each row is
processed. This also applies for any cascading triggers. (See “Cascading
Triggers” on page 2-29.)
• In the FOR EACH ROW section, updating a table with values derived from
the current row of the triggering table. If the triggered actions modify any
row in the table more than once, the final result for that row depends on
the order in which rows from the triggering table are processed.
• Modifying a table in the FOR EACH ROW section that is selected by
another triggered statement in the same FOR EACH ROW section, includ-
ing any cascading triggered actions. If you modify a table in this section
and later refer to it, the changes to the table might not be complete at the
time you refer to it. Consequently, the result might differ depending on
the order in which rows are processed.
The database server does not enforce rules to prevent these situations
because doing so would restrict the set of tables from which a triggered
action can select. Furthermore, the result of most triggered actions is inde-
pendent of row order. Consequently, you are responsible for ensuring that
the results of the triggered actions are independent of row order.
INSERT
REFERENCING
Clause
AS
correlation name is a name you assign to a new column value so that you
can refer to it within the triggered actions. The new col-
umn value is the column value after the triggering state-
ment executes. Once you assign a correlation name, you
can use it only inside the FOR EACH ROW triggered action.
(See “Action Clause Subset” on page 2-20.) The correla-
tion name follows the same syntax rules as other identifi-
ers. (See “Identifier” in Chapter 7 of The Informix Guide to
SQL: Reference.) The correlation name must be unique
within the CREATE TRIGGER statement.
To use the correlation name, precede the column name with the correlation
name, followed by a period. For example, if the new correlation name is post,
you refer to the new value for the column fname as post.fname.
If the trigger event is an INSERT statement, use of the old correlation name as
a qualifier causes an error because no value exists before the row is inserted.
See “Using Correlation Names in Triggered Actions” on page 2-24 for the
rules governing the use of correlation names.
You can use the INSERT REFERENCING clause only if you define a FOR EACH
ROW triggered action.
DELETE
REFERENCING
Clause
AS
correlation name is a name you assign to an old column value so that you
can reference it within the triggered actions. The old col-
umn value in the triggering table is its value before the
triggering statement executes. Once you assign a correla-
tion name, you can use it only inside the FOR EACH ROW
triggered action. (See “Action Clause Subset” on page
2-20.) The correlation name follows the same syntax rules
as other identifiers. (See “Identifier” in Chapter 7 of The
Informix Guide to SQL: Reference.) The correlation name
must be unique within the CREATE TRIGGER statement.
You use the correlation name to refer to an old column value by preceding the
column name with the correlation name and a period (.). For example, if the
old correlation name is pre, you refer to the old value for the column fname
as pre.fname.
If the trigger event is a DELETE statement, use of the new correlation name as
a qualifier causes an error because the column has no value after the row is
deleted. See “Using Correlation Names in Triggered Actions” on page 2-24
for the rules governing the use of correlation names.
You can use the DELETE REFERENCING clause only if you define a FOR EACH
ROW triggered action.
UPDATE
REFERENCING
Clause
1 NEW correlation
name
AS
Action
Clause
(Subset)
FOR EACH Triggered
Action
ROW p. 2-21
Triggered Triggered
BEFORE Action AFTER Action
p. 2-21 p. 2-21
Triggered Action
Triggered
Action
, ,
INSERT
( Statement )
see SQLR
Condition
WHEN ( see SQLR ) DELETE
Statement
see SQLR
UPDATE
Statement
see SQLR
EXECUTE
PROCEDURE
see SQLR
The triggered action consists of an optional WHEN condition and the action
statements. Objects that are referenced in the triggered action—that is, tables,
columns, and stored procedures—must exist when the CREATE TRIGGER
statement is executed. This applies only to objects that are directly referenced
in the trigger definition.
A stored procedure that executes inside the WHEN condition carries the same
restrictions as a stored procedure that is called in a data manipulation state-
ment. See the CREATE PROCEDURE statement in Chapter 7 of The Informix
Guide to SQL: Reference for more information about a stored procedure that is
called within a data manipulation statement.
Using Keywords
If you use the keywords INSERT, DELETE, UPDATE, or EXECUTE as an identi-
fier in any of the following clauses inside the triggered action, you must qual-
ify them by the owner name, or the table name, or both:
• FROM clause of a SELECT statement
• INTO clause of the EXECUTE PROCEDURE statement
• GROUP BY clause
• SET clause of the UPDATE statement
A syntax error is returned if these keywords are not qualified when used in
these clauses inside a triggered action.
If you use the keyword as a column name, it must be qualified by the table
name—for example, table.update. If both the table name and the column
name are keywords, they must be qualified by the owner name—for exam-
ple, owner.insert.update. If the owner name, table name, and column name
are all keywords, the owner name must be in quotes—for example,
"delete".insert.update. The only exception is when these keywords are the
first table or column name in the list. In that case, you do not have to qualify
them. For example, delete in the following statement does not need to be
qualified because it is the first column listed in the INTO clause.
The following examples show instances where you must qualify the column
name or the table name:
GROUP BY clause
For the statement to be valid , both col_c and col_c2 must be columns from
tab1. If col_c2 is intended to be a correlation reference to a column in the trig-
gering table, it must be qualified by either the old or the new correlation
name. If col_c2 is not a column in tab1 and it is not qualified by either the
old or new correlation name, an error is returned.
In a triggered action, an unqualified column name from the triggering table refers to
the current column value, but only when the triggered statement is valid independent
of the triggered action.
Outside the FOR EACH ROW section, you cannot qualify a column from the
triggering table with either the old correlation name or the new correlation
name; thus, it always refers to the current value in the database.
then the first UPDATE statement in the following pair is a valid triggered
action, but the second one is not because it updates column b again:
then in the cascading triggers that follow, trig2 will fail at run time because it
references column b, which is updated by the triggering UPDATE statement.
See “Cascading Triggers” on page 2-29 for more information about cascading
triggers.
new correlation name and the old correlation name do not have any
meaning outside the trigger.
• You cannot use a BEGIN WORK, COMMIT WORK, ROLLBACK WORK, or
SET CONSTRAINTS statement.
When you use a stored procedure as a triggered action, the objects that it ref-
erences are not checked until the procedure is executed.
Cascading Triggers
The database server allows triggers to cascade, meaning that the triggered
actions of a trigger can activate another trigger. The maximum number of
triggers in a cascading sequence is 61, the initial trigger plus a maximum of
60 cascading triggers. When the the number of cascading triggers in a series
exceeds the maximum, the database server returns error number -748:
Exceeded limit on maximum number of cascaded triggers.
Cascading triggers
Note that when you are using either the INFORMIX-SE database server, or the
INFORMIX-OnLine database server without logging, primary key con-
straints on both the manufact and stock tables would prohibit the triggers in
this example. When you use INFORMIX-OnLine with logging, the triggers
execute successfully because constraint checking is deferred until the trig-
gered actions are complete, including the actions of cascading triggers. See
“Constraint Checking” on page 2-30 for more information about how con-
straints are handled when triggers execute.
Constraint Checking
For an INFORMIX-OnLine database with logging, OnLine defers constraint
checking on the triggering statement until the statements in the triggered
action list execute. OnLine effectively executes a SET CONSTRAINTS ALL
DEFERRED statement before executing the triggering statement. At the com-
pletion of the triggered action, it effectively executes a SET CONSTRAINTS
constr_name IMMEDIATE statement to immediately check the constraints that
were deferred. This allows you to write triggers in such a way that the trig-
gered action can resolve any constraint violations that the triggering
statement creates.
Consider the following example, in which the table child has constraint r1
that references the table parent. You define trigger trig1 and activate it with
an INSERT statement. In the triggered action, trig1 checks to see if parent has
a row with the value of the current cola in child. If not, it inserts it.
When you insert a row to a table that is the child table in a referential con-
straint, the row might not exist in the parent table. The database server does
not immediately return this error on a triggering statement. Instead, it allows
the triggered action to resolve the constraint violation by inserting the corre-
sponding row into the parent table. As shown in the example, within the trig-
gered action you can check whether the parent row exists and, if so, bypass
the insert.
For an INFORMIX-OnLine database without logging, OnLine does not defer
constraint checking on the triggering statement. In this case, it immediately
returns an error if the triggering statement violates a constraint.
UPDATE stores5@dbserver1:newtab
SET qty = qty * 2 WHERE s_num = 5
AND mc = “ANZ”;
Note that the row action of the triggering statement occurs before the trig-
gered actions in the FOR EACH ROW section. If the triggered action fails for a
database without logging, the application must restore the row that was
changed by the triggering statement to its previous value.
When you use a stored procedure as a triggered action, if you terminate the
procedure in an exception-handling section, any actions that modify data
inside that section are rolled back along with the triggering statement. For
example, in the following excerpt, when the exception handler traps an error
it inserts a row into the logtab table.
ON EXCEPTION IN (-201)
INSERT INTO logtab values (errno, errstr);
RAISE EXCEPTION -201
END EXCEPTION
When the RAISE EXCEPTION statement returns the error, however, the data-
base server rolls back this insert because it is part of the triggered actions. If
the procedure is executed outside a triggered action, the insert is not rolled
back.
The stored procedure that implements a triggered action cannot contain any
BEGIN WORK, COMMIT WORK, or ROLLBACK WORK statements. If the data-
base has logging, you must either begin an explicit transaction before the trig-
gering statement, or the statement itself must be an implicit transaction. In
any case, another transaction-related statement cannot appear inside the
stored procedure.
You can use triggers to enforce referential actions that the database server
does not currently support. Again, however, for an INFORMIX-SE database
or for an INFORMIX-OnLine database without logging, you are responsible
for maintaining data integrity when the triggering statement fails.
DROP TRIGGER
Purpose
Use the DROP TRIGGER statement to drop a trigger definition from a table.
Syntax
DB
E/C Trigger
DROP TRIGGER Name
E/CO p. 2-11
+
Usage
You must be the owner of the trigger or the DBA to drop a trigger.
The following statement drops the items_pct trigger:
You cannot drop a trigger inside a stored procedure if the procedure is called
within a data manipulation statement. For example, in the following INSERT
statement, a DROP TRIGGER statement is illegal inside the stored procedure
proc1:
Notices
A
IBM may not offer the products, services, or features discussed
in this document in all countries. Consult your local IBM repre-
sentative for information on the products and services currently
available in your area. Any reference to an IBM product,
program, or service is not intended to state or imply that only
that IBM product, program, or service may be used. Any
functionally equivalent product, program, or service that does
not infringe any IBM intellectual property right may be used
instead. However, it is the user’s responsibility to evaluate and
verify the operation of any non-IBM product, program, or
service.
IBM may have patents or pending patent applications covering
subject matter described in this document. The furnishing of this
document does not give you any license to these patents. You
can send license inquiries, in writing, to:
Any references in this information to non-IBM Web sites are provided for
convenience only and do not in any manner serve as an endorsement of those
Web sites. The materials at those Web sites are not part of the materials for
this IBM product and use of those Web sites is at your own risk.
IBM may use or distribute any of the information you supply in any way it
believes appropriate without incurring any obligation to you.
Licensees of this program who wish to have information about it for the
purpose of enabling: (i) the exchange of information between independently
created programs and other programs (including this one) and (ii) the mutual
use of the information which has been exchanged, should contact:
IBM Corporation
J74/G4
555 Bailey Ave
P.O. Box 49023
San Jose, CA 95161-9023
U.S.A.
The licensed program described in this information and all licensed material
available for it are provided by IBM under terms of the IBM Customer
Agreement, IBM International Program License Agreement, or any equiv-
alent agreement between us.
All IBM prices shown are IBM’s suggested retail prices, are current and are
subject to change without notice. Dealer prices may vary.
Notices A-3
Trademarks
Each copy or any portion of these sample programs or any derivative work,
must include a copyright notice as follows:
If you are viewing this information softcopy, the photographs and color illus-
trations may not appear.
Trademarks
AIX; DB2; DB2 Universal Database; Distributed Relational Database
Architecture; NUMA-Q; OS/2, OS/390, and OS/400; IBM Informix;
C-ISAM; Foundation.2000TM; IBM Informix 4GL; IBM Informix
DataBlade Module; Client SDKTM; CloudscapeTM; CloudsyncTM;
IBM Informix Connect; IBM Informix Driver for JDBC; Dynamic
ConnectTM; IBM Informix Dynamic Scalable ArchitectureTM (DSA);
IBM Informix Dynamic ServerTM; IBM Informix Enterprise Gateway
Manager (Enterprise Gateway Manager); IBM Informix Extended Parallel
ServerTM; i.Financial ServicesTM; J/FoundationTM; MaxConnectTM; Object
TranslatorTM; Red Brick Decision ServerTM; IBM Informix SE;
IBM Informix SQL; InformiXMLTM; RedBack; SystemBuilderTM; U2TM;
UniData; UniVerse; wintegrate are trademarks or registered trademarks
of International Business Machines Corporation.
Java and all Java-based trademarks and logos are trademarks or registered
trademarks of Sun Microsystems, Inc. in the United States and other
countries.
Windows, Windows NT, and Excel are either registered trademarks or trade-
marks of Microsoft Corporation in the United States and/or other countries.
Other company, product, and service names used in this publication may be
trademarks or service marks of others.
Error Messages
This section contains a list of the Informix error messages
that the database server can return when you create or use
triggers. The list contains both new and changed messages.
The messages are listed in ascending order with each error
message followed by a corrective action.
-730 Cannot specify REFERENCING if trigger does not have FOR EACH ROW.
You included a REFERENCING clause in a CREATE TRIGGER statement that
does not include a FOR EACH ROW triggered action section. Either remove
the REFERENCING clause or, if it is appropriate, add the missing keywords
FOR EACH ROW, followed by the triggered actions that are to occur at that
time.
2 Error Messages
-732 Incorrect use of old or new values correlation name inside trigger.
You cannot use the new or old correlation name outside the FOR EACH ROW
section, or in the INTO clause of the EXECUTE PROCEDURE statement. It is
also not valid to use the new or old correlation name to qualify the SELECT
COUNT DISTINCT column. For example, the following statement returns
error -732:
You cannot specify an old correlation name for an insert trigger. You cannot
specify a new correlation name for a delete trigger.
Error Messages 3
-744 Illegal SQL statement in trigger.
This error is returned when the triggered SQL statement is BEGIN WORK,
COMMIT WORK, ROLLBACK WORK, or SET CONSTRAINTS. These statements
are not allowed as triggered actions. Remove the offending statement.
-746 message-string
This is a message for which you supply message-string. You can apply this
message to error conditions that you specify in a stored procedure that is a
triggered action. The corrective action for this error depends on the condition
that caused it. Both the condition and the message text are defined by you,
the user.
4 Error Messages
triggered action. A pre-5.01 database server is not equipped to check for this,
so the procedure is disallowed. If possible, execute the procedure on a 5.01
database server.
Error Messages 5
6 Error Messages
Index
Index
Special symbols are listed in ASCII order at the end of the index.
A
Action clause
AFTER 2-15
consists of 1-5
definition of 2-14
example 1-5
FOR EACH ROW 2-14
keywords 1-5
syntax 2-14
Action clause subset, syntax 2-20
Action statements
in triggered action clause 2-22
list of 2-22
order of execution 2-22
Adding comments
ANSI-compliant method 1-6
non-ANSI-compliant method 1-6
to CREATE TRIGGER statement 1-6, 1-8
AFTER action 2-15
AFTER keyword 1-5, 2-15
ALTER TABLE statement 2-36
Applications for triggers 1-10
B
BEFORE keyword 1-5, 2-14
BEGIN WORK statement 2-28
Braces, adding comments with 1-6
C CREATE TRIGGER statement
action clause 1-5
Cascading triggers adding comments 1-6, 1-8
and triggering table 2-26, 2-30 comments outside 1-7
description of 2-29 comments within 1-7
INFORMIX-OnLine 1-17 elements of 1-4
INFORMIX-SE 1-17 embedding in a program 1-7
maximum number of 1-17, 2-29 in ESQL/C 2-8
scope of correlation names 2-24 in ESQL/COBOL 2-8
triggered actions 2-16 privilege to use 2-8
Client/server environment 2-32 purpose 2-7
Column name REFERENCING clause 1-5
in UPDATE clause 2-12 syntax 2-7
when qualified 2-23 trigger event 1-4
Column numbers, effect on triggers 2-13 trigger name 1-4
triggered action clause 2-21
Column value usage 2-8
in triggered action 2-25
qualified vs. unqualified 2-25 Creating a trigger
when unqualified 2-25 CREATE TRIGGER statement 1-4
using DB-Access 1-6
Comments, including in CREATE using ESQL/C 1-7
TRIGGER statement 1-6 using ESQL/COBOL 1-7
COMMIT WORK statement 2-28 Creating an audit trail
Constraint checking 2-30 example 1-10
Conventions using triggers 1-10
syntax Intro-5 Cursor statement, as trigger event 2-9
typographical Intro-5
Correlation name
and stored procedures 2-24
D
in COUNT DISTINCT clause 2-24 Dashes, adding comments with 1-6
in DELETE REFERENCING clause Database, stores5 Intro-13
2-18 datakey column, in systrigbody table 1-8
in GROUP BY clause 2-24
in INSERT REFERENCING clause DB-Access
2-17 creating a trigger with 1-6
in SET clause 2-24 looking up a trigger header 1-9
in stored procedure 2-27 QUERY-LANGUAGE Menu 1-6
in UPDATE REFERENCING clause DELETE REFERENCING clause
2-19 and FOR EACH ROW section 2-20
new 2-19 correlation name 2-18
old 2-19 syntax 2-18
rules for 2-24 DELETE statement
scope of 2-24 as triggering statement 2-9
table of values 2-25 in trigger event 2-8
using 2-24 in triggered action 2-22
when to use 2-24 Demonstration database
COUNT DISTINCT clause 2-24 copying Intro-14
CREATE SCHEMA statement installation script Intro-13
and CREATE TRIGGER statement overview Intro-13
2-36 Deriving data, use of triggers in 1-14
defining a trigger 2-8 Documentation notes Intro-10
2 Index
Documentation, other useful Intro-4 I
DROP DATABASE statement 2-36
Icon, explanation of Intro-6
DROP TABLE statement 2-36
Informix products, application
DROP TRIGGER statement development tools Intro-3
syntax 2-35
use of 2-35 INFORMIX-OnLine
and triggering statement 2-9
with logging 1-16
E INFORMIX-SE, cascading triggers 1-17
Embedding in a program INSERT REFERENCING clause
CREATE TRIGGER statement 1-7 and FOR EACH ROW section 2-20
in ESQL/C 1-7 correlation name 2-17
in ESQL/COBOL 1-7 syntax 2-17
Enforcing referential integrity 1-16 INSERT statement
Error messages in trigger event 2-8
number -745 1-18 in triggered action 2-22
number -746 1-18
on SQL statements 1-18
retrieving text in a program 1-19, 1-21
K
text for error number -746 1-20 Keywords
user-specified 1-18 AFTER 1-5, 2-14
using RAISE EXCEPTION statement BEFORE 1-5, 2-14
1-19 FOR EACH ROW 1-5, 2-14
Example NEW 2-18, 2-19
creating an audit trail 1-10 OLD 2-17, 2-18
deriving data 1-14 using in triggered action 2-22
enforcing referential integrity 1-16
implementing a business rule 1-12 L
EXECUTE PROCEDURE statement, in Looking up a trigger 1-8
triggered action 2-22
F M
Machine notes Intro-10
FOR EACH ROW action
SELECT statement in 2-16 Multiple triggers
triggered action list 2-14 column numbers in 2-13
example 2-12
order of execution 2-13
G preventing overriding 2-31
GROUP BY clause 2-24
N
H NEW keyword
Header information in DELETE REFERENCING clause
consists of 1-9 2-18
for a trigger 1-9 in INSERT REFERENCING clause
2-17
in UPDATE REFERENCING clause
2-19
Index 3
O DBA-privileged 2-28
in WHEN condition 2-22
OLD keyword owner-privileged 2-28
in DELETE REFERENCING clause passing data to 1-15
2-18 privileges 2-28
in INSERT REFERENCING clause tracing triggered actions 1-17
2-17 Stored Procedure Language (SPL)
in UPDATE REFERENCING clause SET DEBUG FILE TO 1-17
2-19 TRACE command 1-17
On-line using trace commands 1-17
files Intro-10 stores5 database
help Intro-10 copying Intro-14
Order of execution, of action statements creating on INFORMIX-OnLine
2-22 Intro-14
Output from TRACE command 1-18 creating on INFORMIX-SE Intro-15
overview Intro-13
P Syntax diagram
conventions Intro-5
PREPARE statement 2-36 elements of Intro-8
Privileges, for triggered action 2-28 System catalog tables
PUT statement, impact on trigger 2-9 for triggers 2-3
systrigbody 1-8
systriggers 1-8
R systrigbody table
REFERENCING clause contents of 2-5
defining 1-5 datakey column in 1-8
DELETE REFERENCING clause 2-18 index 2-5
INSERT REFERENCING clause 2-17 systriggers table
UPDATE REFERENCING clause 2-19 content of 2-4
using referencing 2-24 indexes 2-4
Release notes Intro-10 querying 1-8
RENAME COLUMN statement 2-36 trigid column 1-9
RENAME TABLE statement 2-36
Result of triggering statement 2-22 T
ROLLBACK WORK statement 2-28 TRACE command
Row order, guaranteeing independence output from 1-18
of 2-15 using 1-17
Rules for stored procedures 2-27 Trigger
and other SQL statements 2-36
S benefits of 1-3
consists of 1-3
SELECT statement, in FOR EACH ROW definition of 1-3
section 2-16 header information 1-8
SET clause 2-24 in client/server environment 2-32
SET CONSTRAINT statement 2-28, 2-30 looking up 1-8
SPL. See Stored Procedure Language. number on a table 2-8
preventing overriding 2-31
Stored procedure trigger name 1-4
as triggered action 2-27 uses for 1-4
checking references 2-28
4 Index
Trigger event Triggering table
definition of 1-4, 2-8 action on 2-26
in CREATE TRIGGER statement 2-8 and cascading triggers 2-30
INSERT 2-17 trigid column, in systriggers table 1-9
privileges on 2-9 Typographical conventions Intro-5
with cursor statement 2-9
Trigger name, syntax 2-11
Triggered action
U
action on triggering table 2-26 UPDATE clause, syntax 2-12
anyone can use 2-28 UPDATE REFERENCING clause
avoiding dependence on row order and FOR EACH ROW section 2-20
2-15 correlation name 2-19
cascading 2-16 syntax 2-19
clause 2-21 UPDATE statement
component of trigger 1-3 as triggered action 2-22
correlation name in 2-24, 2-27 as triggering statement 2-9, 2-12, 2-13
definition of 1-3 in trigger event 2-8
FOR EACH ROW 2-15
in client/server environment 2-32 Update trigger, defining multiple 2-12
merged 2-15 Using correlation names 2-24
occurs 1-5 Using triggers
preventing overriding 2-31 automating changes 1-10
WHEN condition 2-21 constructing before and after images
Triggered action clause 1-12
action statements 2-22 deriving data 1-14
syntax 2-21 implementing business rules 1-12
WHEN condition 2-21 some applications 1-10
Triggered action list
AFTER 2-15 W
BEFORE 2-14
FOR EACH ROW 2-14 WHEN condition
for multiple triggers 2-15 in triggered action 2-21
sequence of 2-14 restrictions 2-22
use of 2-21
Triggering statement
affecting multiple rows 2-15 WHERE CURRENT OF clause, impact
component of trigger 1-3 on trigger 2-9
execution of 2-10
guaranteeing same result 2-8 Symbols
result of 2-22
types of 1-3 --, adding comments with 1-6
UPDATE 2-13 {}, adding comments with 1-6
Index 5
6 Index