SQL/MX 3.2.1 Reference Manual (H06.26+, J06.15+)
SQL/MX Statements
HP NonStop SQL/MX Release 3.2.1 Reference Manual—691117-005
2-150
Examples of CREATE TRIGGER
Trigger temporary table is a table associated with the subject table of the trigger and is
used to store intermediate results during trigger execution. In the example, error is
returned because of the way trigger temporary tables are created. The temporary table
is created with two more columns than its corresponding subject table. The combined
length of the additional columns is 16 bytes. The two added columns, along with the
subject table’s primary key, form the primary key of the temporary table. This primary
key is too long.
If you update the length of column c1 of table t1 from varchar (2040) to a varchar of
2032 or less bytes (for example, varchar (2000)), the CREATE TRIGGER statement
completes successfully.
Rowsets
SQL/MX rowsets are allowed in UPDATE and DELETE statements that are trigger
events.
UPDATE and DELETE statements that use rowset arrays perform multiple executions
of UPDATE or DELETE statements. UPDATE and DELETE statement triggers behave
as a sequence of statement triggers that are triggered once for each value in the array
of values in the rowset.
This behavior is different from a row trigger because each value in the rowset might
match multiple rows in the subject table. Therefore, multiple rows might be affected
(updated or deleted) before the action of the trigger is executed.
Contrast this behavior with row triggers where the trigger action is executed once for
each affected row.
For INSERT statement that use rowsets, an INSERT statement trigger is triggered
once for the entire rowset.
Examples of CREATE TRIGGER
Before and After Triggers
Suppose that you have a database to record patients’ vital signs and drugs prescribed
for them. The database consists of these tables:
•
vital_signs, which records vital signs at each visit
•
prescription, which records prescriptions written for each patient
•
generic_drugs, which lists generic drug equivalents for brand-name drugs
The prescription table is created like this:
CREATE TABLE prescription
( id INTEGER NOT NULL
Note. If you want to create triggers on a table, its primary key length cannot exceed 2032
bytes. A table that does not include triggers can have a primary key of 2048 bytes.










