473,473 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

SQL0101N and SQL0723N - Recursive Triggers Should Not be Happening

I want to insert a row into an ITEM table if certain SKUs are inserted.
There are two triggers where each looks for a particular SKU and inserts the
appropriate matching row in the same table. However when a record is
inserted, the following error message occurs:

Under DB2 UDB v7.2
[IBM][CLI Driver][DB2/NT] SQL0101N The statement is too long or too
complex. LINE NUMBER=2. SQLSTATE=54001

Under DB2 UDB v8.1
[IBM][CLI Driver][DB2/NT] SQL0723N An error occurred in a triggered SQL
statement in trigger "DBA.ITEM_B". Information returned for the error
includes SQLCODE "-101", SQLSTATE "54001" and message tokens "".
SQLSTATE=09000

Both messages point to a recursion of triggers. This seems to be confirmed
by dropping either of the two triggers. The trouble is the condition for
the triggers should never happen. I've provided sample SQL statements below
to recreate the situation. Why is this happening? Thanks in advance.

CREATE TABLE ITEM (
ORDER_NO CHARACTER(10) NOT NULL,
SKU_NO CHARACTER(10) NOT NULL,
UNITS INTEGER NOT NULL
)
;

CREATE TRIGGER ITEM_A AFTER INSERT ON ITEM REFERENCING NEW AS N_ROW FOR EACH
ROW MODE DB2SQL WHEN
(
n_row.sku_no = 'A1'
)
begin atomic
INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES (N_ROW.ORDER_NO, 'A2', 1);
end

CREATE TRIGGER ITEM_B AFTER INSERT ON ITEM REFERENCING NEW AS N_ROW FOR EACH
ROW MODE DB2SQL WHEN
(
n_row.sku_no = 'B1'
)
begin atomic
INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES (N_ROW.ORDER_NO, 'B2', 1);
end

INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES
('100', 'C1', 1);
Nov 12 '05 #1
1 5892
Michael wrote:
I want to insert a row into an ITEM table if certain SKUs are inserted.
There are two triggers where each looks for a particular SKU and inserts the
appropriate matching row in the same table. However when a record is
inserted, the following error message occurs:

Under DB2 UDB v7.2
[IBM][CLI Driver][DB2/NT] SQL0101N The statement is too long or too
complex. LINE NUMBER=2. SQLSTATE=54001

Under DB2 UDB v8.1
[IBM][CLI Driver][DB2/NT] SQL0723N An error occurred in a triggered SQL
statement in trigger "DBA.ITEM_B". Information returned for the error
includes SQLCODE "-101", SQLSTATE "54001" and message tokens "".
SQLSTATE=09000

Both messages point to a recursion of triggers. This seems to be confirmed
by dropping either of the two triggers. The trouble is the condition for
the triggers should never happen. I've provided sample SQL statements below
to recreate the situation. Why is this happening? Thanks in advance.

CREATE TABLE ITEM (
ORDER_NO CHARACTER(10) NOT NULL,
SKU_NO CHARACTER(10) NOT NULL,
UNITS INTEGER NOT NULL
)
;

CREATE TRIGGER ITEM_A AFTER INSERT ON ITEM REFERENCING NEW AS N_ROW FOR EACH
ROW MODE DB2SQL WHEN
(
n_row.sku_no = 'A1'
)
begin atomic
INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES (N_ROW.ORDER_NO, 'A2', 1);
end

CREATE TRIGGER ITEM_B AFTER INSERT ON ITEM REFERENCING NEW AS N_ROW FOR EACH
ROW MODE DB2SQL WHEN
(
n_row.sku_no = 'B1'
)
begin atomic
INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES (N_ROW.ORDER_NO, 'B2', 1);
end

INSERT INTO ITEM
(ORDER_NO, SKU_NO, UNITS)
VALUES
('100', 'C1', 1);

The problem is not one of runtime (i.e. whether DB2 enters teh recursion.
It is about compile time. DB2 tries to expand all _possible_ recursions
16 levels deep.
So the one insert can trigger two inserts which can trigger two inserts.
All in all you end up with 32,000 _possible_ INSERTS. No wonder it blows.
In your example teh fix is simple:
Unify teh two INSERT statements by unifying the two triggers.
I.e. INSERT INTO item VALUES (<row>), (<row>);
This way there is no fan out and DB2 expands only for 16 inserts.
If your real trigger is a lot bigger you may still need to increase the
statement heap a bit, but it will be managable.

Cheers
Serge
--
Serge Rielau
DB2 SQL Compiler Development
IBM Toronto Lab
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hank | last post by:
I have two SQL Server 2000 machines (server_A and server_B). I've used sp_addlinkedserver to link them both, the link seems to behave fine. I can execute remote queries and do all types of neat...
11
by: raulgz | last post by:
I need audit triggers that change columns value in the same record that fire trigger. I need how to do.. Thanks..
6
by: Hardy | last post by:
One of my customers have a sql statement totaled more than 400 lines, about 40KB. when excuted, error arrised saying "SQL0101N The statement is too long or too complex". I tried one of his...
7
by: urban.widmark | last post by:
Hello We are having some problems with triggers, sequences and union all in V8 on code that worked fine in V7. Was wondering if someone else has seen this and/or knows what to do. A trigger...
8
by: Andy | last post by:
Hi all, i am pretty new to programming and have a (simple?) problem here: I want to populate a Treeview with data from a table. Table layout is: ID, ParentID, Description There can be...
7
by: aj | last post by:
DB2 LUW 8.2 FP5 (or is it 8.1 FP11?) I am CALLing a stored procedure from a trigger in order to maintain a column-level audit trail. Not only do I need to store a record of the INSERT, but also...
5
by: Michel Esber | last post by:
Audit trigger Hello, LUW DB2 V8 FP13 I am trying to create audit triggers in order to find out which user/application is deleting data from a table, as well as the statement the user...
3
by: Eric Davidson | last post by:
DB2 9.5 I keep geting the message. SQL0101N The statement is too long or too complex. SQLSTATE=54001 When one of my sql statements takes over 60 seconds to compile the sql statement. Is...
0
by: aj | last post by:
DB2 8.2 FP14 LUW Red Hat AS Interesting one here. I modified a trigger body yesterday, changing a numeric constant used in in INSERT statement. I did not add any SQL to the trigger.. The...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.