Scalable Database Server, HiRDB Version 8 Description

[Contents][Glossary][Index][Back][Next]

5.5 Triggers

By defining a trigger, you can have SQL statements automatically execute when an operation (updating, insertion, deletion) is performed on a particular table. A trigger defines such specifications as the table to which the trigger applies, the SQL statement that activates the trigger (trigger event SQL), the SQL statements that are to be executed automatically (trigger SQL statements), and conditions for execution of the action (trigger action search conditions). When an SQL statement that satisfies the trigger action search conditions is executed on a table for which a trigger is defined, the trigger SQL statements are automatically executed. Figure 5-6 provides an overview of triggers.

Figure 5-6 Overview of triggers

[Figure]

Explanation
A trigger is defined to provide cumulative updating of data in the product management historical table on price changes that occur in the product management table. In this example, when the trigger event SQL statement (UPDATE in this case) is executed from the UAP, the product number, the price before the change, and the price after the change in the row containing the changed price are added to the product management historical table.

Note, however, that when you define a trigger for a table, you must re-generate any function, procedure, or trigger SQL object that uses that table, because any SQL object that uses that table becomes invalid. Similarly, if you define, change, or delete any resources that are used by the trigger (tables, indexes, and so on), the trigger SQL object becomes invalid, so you must re-generate it as well. For details, see the HiRDB Version 8 Installation and Design Guide.

Organization of this section
(1) Application criteria
(2) Before you define a trigger
(3) Trigger definition statements

(1) Application criteria

Consider using a trigger to perform the following actions when an associated UAP operation occurs:

(2) Before you define a trigger

When you define a trigger, an SQL object that codes the specified trigger action procedure is automatically generated and stored in the corresponding data dictionary LOB RDAREA. Thus, before you define a trigger, you must make sure that the data dictionary LOB RDAREA has sufficient capacity. For details about how to estimate the capacity of data dictionary LOB RDAREAs, see the HiRDB Version 8 Installation and Design Guide.

In addition, if you plan to execute trigger event SQL statements, you must also take into consideration the trigger SQL object size when you specify the buffer length for SQL objects. For details about how to estimate the buffer length for SQL objects, see the manual HiRDB Version 8 System Definition.

(3) Trigger definition statements

The following definition SQL statements are used to define a trigger, to re-generate an SQL object, and to delete a trigger.

CREATE TRIGGER
This statement defines a trigger. You can define triggers only for tables that you own. You cannot define triggers for tables owned by other users.

ALTER TRIGGER
This statement re-generates the SQL object of a trigger that has already been defined. You can also use the ALTER ROUTINE statement to re-generate SQL objects.

DROP TRIGGER
This statement deletes a trigger.