Skip to content Skip to sidebar Skip to footer

Db2 Equivalent Of Sql Server's Trigger_nestlevel()?

I'm trying to get control of a recursive trigger over DB2 (v9.7), unfortunately IBM documentation doesn't mention a way to know at which level of recursion the current trigger call

Solution 1:

Unfortunately DB2 does NOT have any function or stored procedure for this. You can have maximum of 16 trigger cascade levels.

It is hard coded and can not be changed.

BTW in DB2, if a trigger causes another trigger to be fired, it is called trigger cascade. And you can avoid cascading by NO CASCADE keyword.

If you want to avoid the call to same trigger, there is a workaround:

  1. Create a view for your table => Create View vTable1 as Select * from Table1
  2. Create an INSTEAD OF TRIGGER for vTable1. => CREATE TRIGGER TRG_INSERT INSTEAD OF INSERT ON vTable1
  3. In TRG_INSERT, to insert into to table1.

Post a Comment for "Db2 Equivalent Of Sql Server's Trigger_nestlevel()?"