DB2 equivalent of SQL Server's TRIGGER_NESTLEVEL()?

与世无争的帅哥 提交于 2019-12-10 17:18:36

问题


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 is in.

I've found that there's this function on sql-server: trigger_nestlevel(), it basically does what I want (knowing the actual trigger recursive call level). so I would like to know if there is an equivalent function in DB2.


回答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.


来源:https://stackoverflow.com/questions/13845776/db2-equivalent-of-sql-servers-trigger-nestlevel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!