May 19, 2012, Saturday, 139


Example Trigger with SIGNAL

From SQL PL Guide for DB2

Jump to: navigation, search

Example: Before Trigger who's checking a new value

This BEFORE TRIGGER is checking the inserted value in the column hiredate. If the hiredate is in the future the trigger raise the SQLSTATE 75000 and the insert fails:

create trigger CHECK_HIREDATE
no cascade before insert on EMPLOYEE
referencing new as N
for each row mode db2sql
if n.hiredate > current date
then
  signal SQLSTATE '75000'
  set MESSAGE_TEXT = 'Hire date must be in the past';
end if!