Trigger Template Items

Trigger template items are named reusable blocks of script that can be inserted into triggers or trigger templates. In a generated trigger script, a template item calls a macro that implements a trigger referential integrity constraint or does any other updating work on tables in the database.

To insert a trigger template item into your trigger or template definition, click the Add Trigger Item from Model or Add Trigger Item from DBMS tool, select the items from the list and click OK. The item is inserted with a dot followed by its name, and is also added to the list on the Template Items tab. For example, the following script contains two template items InsertChildParentExist and InsertTooManyChildren:

/*  Before insert trigger "%TRIGGER%" for table "[%QUALIFIER%]%TABLE%"  */
create trigger %TRIGGER% before insert order %ORDER% on [%QUALIFIER%]%TABLE%
referencing new as new_ins for each row
begin
  declare user_defined_exception exception for SQLSTATE '99999';
  declare found integer;
  .InsertChildParentExist
  .InsertTooManyChildren
end
/
Note: Certain DBMSs require that a cursor and variables are declared for each template item before the template item name is used in the script. You can use the following format to declare a template item:
.Decltemplate item name
For example, the trigger definition for Oracle 8 declares and then inserts the .InsertChildParentExist template item:
--  Before insert trigger "[%QUALIFIER%]%TRIGGER%" for table "[%QUALIFIER%]%TABLE%"
create trigger [%QUALIFIER%]%TRIGGER% before insert
on [%QUALIFIER%]%TABLE% for each row
declare
  integrity_error  exception;
  errno    integer;
  errmsg     char(200);
  dummy    integer;
  found    boolean;
  .DeclInsertChildParentExist
begin
  .InsertChildParentExist
--  Errors handling
exception
  when integrity_error then
   raise_application_error(errno, errmsg);
end;
/
To review or modify the provided trigger template items, select Database > Edit Current DBMS, and then click the Trigger Template Items tab. You cannot delete or rename these items.
Warning!  The resource files provided with PowerDesigner inside the Program Files folder cannot be modified directly. To create a copy for editing, use the New tool on the resource file list, and save it in another location. To include resource files from different locations for use in your models, use the Path tool on the resource file list.
To create a new template item, click the Create from DBMS Trigger Item tool (to copy the code of an existing item to your new item) or the Add a Row tool (to start from scratch).
Note: You can, alternatively, create trigger template items in your model by selecting Model > Triggers > Trigger Template Items, but these templates will not be accessible from other models.

Trigger Template Item Properties

The General tab contains the following properties:

Property

Description

Name/Code/Comment

Identify the object. The name should clearly convey the object's purpose to non-technical users, while the code, which is used for generating code or scripts, may be abbreviated, and should not normally include spaces. You can optionally add a comment to provide more detailed information about the object. By default the code is generated from the name by applying the naming conventions specified in the model options. To decouple name-code synchronization, click to release the = button to the right of the Code field.

DBMS

Specifies the parent DBMS.

Keywords

Provide a way of loosely grouping objects through tagging. To enter multiple keywords, separate them with commas.

The following tabs are also available:
  • Definition - Contains a field for entering the trigger code for the item.You can use PDM variables and macros and other tools available from the toolbar (see Writing SQL Code in PowerDesigner).
  • Declaration - Contains a field for entering the declaration for the item in trigger scripts.