Chapter 5 Building Triggers and Procedures
Trigger template items are named reusable blocks of script that can be inserted into trigger templates or triggers.
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.
A trigger template for Sybase Adaptive Server Anywhere 6 contains the .InsertChildParentExist
template item, which corresponds to the following definition:
.FOREACH_PARENT()
/* Parent "[%PQUALIFIER%]%PARENT%" must exist when inserting a child in "[%CQUALIFIER%]%CHILD%" */
if (.JOIN("new_ins.%FK% is not null", "", " and", ") then")
begin
set found = 0;
select 1
into found
from dummy
where exists (select 1
from [%PQUALIFIER%]%PARENT%
where .JOIN("%PK% = new_ins.%FK%", "and ", "", ");")
if found <> 1 then
message 'Error: Trigger(%TRIGGER%) of table [%QUALIFIER%]%TABLE%';
message ' Parent code must exist when inserting a child!';
signal user_defined_exception;
end if;
end
end if;
.ENDFOR
| Copyright (C) 2005. Sybase Inc. All rights reserved. |
| |