Search code examples
databasetriggersdb2database-triggerdb2-express-c

DB2 before trigger


I've got this trigger:

--#SET TERMINATOR @
CREATE TRIGGER actualizarSaldoIngreso
BEFORE INSERT ON Ingreso
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
    UPDATE Cliente SET Nombre = 'Juan' WHERE DNI = '87366034M';
END@
--#SET TERMINATOR ;

But db2 returns the following error:

The trigger "DB2INST1.ACTUALIZARSALDOINGRESO" is defined with an unsupported triggered SQL statement

Any ideas why?


Solution

  • It's stated in the CREATE TRIGGER description:

    The SQL-procedure-statement in a BEFORE trigger cannot:

    Contain any INSERT, DELETE, or UPDATE operations, nor invoke any routine defined with MODIFIES SQL DATA, if it is not a compound SQL (compiled).

    Remove the ATOMIC clause or use an AFTER INSERT trigger.