473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How I can delete rows in one table with foreign keys

Hello to all and thanks for answer to my topics.
I made one stored procedure that delete one table, but when
call/execute the procedure this show

SQL0532N A parent row cannot be deleted because the relationship
"TXN_TRANSACTION.FK_SCLI " restricts the deletion.

Then in the procedure it adds one delete of the foreign keys. This it
is the procedure

CREATE procedure eis.DeleteUpdate()
begin atomic
declare txtdrop varchar(1000);
declare txtadd varchar(1000);

SET txtdrop = 'ALTER TABLE EIS.CLI_CLIENT DROP CONSTRAINT
SQL051102111045710';
EXECUTE IMMEDIATE txtdrop;
FOR V1 AS
SELECT
B.CLIENTID AS IDCLIENTID,
B.MAPPEDCLIENTID AS MAPPED
FROM EIS.CLI_MAPING B
WHERE
STATUSID = 3 AND
CLIENTID != MAPPEDCLIENTID
DO

DELETE FROM EIS.CLI_BANK
WHERE CLIENTID = IDCLIENTID;

DELETE FROM EIS.CLI_CLIENT
WHERE CLIENTID = IDCLIENTID;
END FOR;

SET txtadd = 'ALTER TABLE EIS.CLI_CLIENT
ADD CONSTRAINT SQL051102111045710 PRIMARY KEY (CLIENTID)';
EXECUTE IMMEDIATE txtadd;
end
But when call this stored procedure show the following message

SQL0910N The SQL statement cannot access an object on which a
modification is
pending. SQLSTATE=57007
SQL0910N The SQL statement cannot access an object on which a
modification is pending.

What I really need with the procedure is that it allows me to delete
registries or rows of the table.
Greetings

Iván

Sep 7 '06 #1
6 9703
Hi, Ivan:

OK--just dealing with the error you've reported (as opposed to talking
about your design/approach), it looks like you're dealing with the
second bullet-item under the help description for this error code
(execute "? SQL-0910N" in a command editor and you'll see what I mean).
Can you tell us what your autocommit setting is when executing the SP?

--Jeff

Ivan wrote:
Hello to all and thanks for answer to my topics.
I made one stored procedure that delete one table, but when
call/execute the procedure this show

SQL0532N A parent row cannot be deleted because the relationship
"TXN_TRANSACTION.FK_SCLI " restricts the deletion.

Then in the procedure it adds one delete of the foreign keys. This it
is the procedure

CREATE procedure eis.DeleteUpdate()
begin atomic
declare txtdrop varchar(1000);
declare txtadd varchar(1000);

SET txtdrop = 'ALTER TABLE EIS.CLI_CLIENT DROP CONSTRAINT
SQL051102111045710';
EXECUTE IMMEDIATE txtdrop;
FOR V1 AS
SELECT
B.CLIENTID AS IDCLIENTID,
B.MAPPEDCLIENTID AS MAPPED
FROM EIS.CLI_MAPING B
WHERE
STATUSID = 3 AND
CLIENTID != MAPPEDCLIENTID
DO

DELETE FROM EIS.CLI_BANK
WHERE CLIENTID = IDCLIENTID;

DELETE FROM EIS.CLI_CLIENT
WHERE CLIENTID = IDCLIENTID;
END FOR;

SET txtadd = 'ALTER TABLE EIS.CLI_CLIENT
ADD CONSTRAINT SQL051102111045710 PRIMARY KEY (CLIENTID)';
EXECUTE IMMEDIATE txtadd;
end
But when call this stored procedure show the following message

SQL0910N The SQL statement cannot access an object on which a
modification is
pending. SQLSTATE=57007
SQL0910N The SQL statement cannot access an object on which a
modification is pending.

What I really need with the procedure is that it allows me to delete
registries or rows of the table.
Greetings

Iván
Sep 7 '06 #2
Excuse me, to that you talk about with autocommit setting ?
jefftyzzer wrote:
Hi, Ivan:

OK--just dealing with the error you've reported (as opposed to talking
about your design/approach), it looks like you're dealing with the
second bullet-item under the help description for this error code
(execute "? SQL-0910N" in a command editor and you'll see what I mean).
Can you tell us what your autocommit setting is when executing the SP?

--Jeff

Ivan wrote:
Hello to all and thanks for answer to my topics.
I made one stored procedure that delete one table, but when
call/execute the procedure this show

SQL0532N A parent row cannot be deleted because the relationship
"TXN_TRANSACTION.FK_SCLI " restricts the deletion.

Then in the procedure it adds one delete of the foreign keys. This it
is the procedure

CREATE procedure eis.DeleteUpdate()
begin atomic
declare txtdrop varchar(1000);
declare txtadd varchar(1000);

SET txtdrop = 'ALTER TABLE EIS.CLI_CLIENT DROP CONSTRAINT
SQL051102111045710';
EXECUTE IMMEDIATE txtdrop;
FOR V1 AS
SELECT
B.CLIENTID AS IDCLIENTID,
B.MAPPEDCLIENTID AS MAPPED
FROM EIS.CLI_MAPING B
WHERE
STATUSID = 3 AND
CLIENTID != MAPPEDCLIENTID
DO

DELETE FROM EIS.CLI_BANK
WHERE CLIENTID = IDCLIENTID;

DELETE FROM EIS.CLI_CLIENT
WHERE CLIENTID = IDCLIENTID;
END FOR;

SET txtadd = 'ALTER TABLE EIS.CLI_CLIENT
ADD CONSTRAINT SQL051102111045710 PRIMARY KEY (CLIENTID)';
EXECUTE IMMEDIATE txtadd;
end
But when call this stored procedure show the following message

SQL0910N The SQL statement cannot access an object on which a
modification is
pending. SQLSTATE=57007
SQL0910N The SQL statement cannot access an object on which a
modification is pending.

What I really need with the procedure is that it allows me to delete
registries or rows of the table.


Greetings

Iván
Sep 7 '06 #3
Right. My reasoning is that under the explanation for the error you're
getting, it says (in part):

"The application program attempted to access an object within the
same unit of work in which either:
<SNIP>
The application program issued a statement against the object
that added or dropped a constraint."
<SNIP>

And under the user response section, it says (in part):

"Modify the application program so there is no attempt to access
an object within the same unit of work in which the modification
was made."

So, the issue surrounds units of work. If you've got autocommit turned
off (in which case you need to issue explicit COMMITs after DDL and DML
statements), then it sounds like you need to add a COMMIT after you do
the ALTER.

--Jeff

Ivan wrote:
Excuse me, to that you talk about with autocommit setting ?
jefftyzzer wrote:
Hi, Ivan:

OK--just dealing with the error you've reported (as opposed to talking
about your design/approach), it looks like you're dealing with the
second bullet-item under the help description for this error code
(execute "? SQL-0910N" in a command editor and you'll see what I mean).
Can you tell us what your autocommit setting is when executing the SP?

--Jeff

Ivan wrote:
Hello to all and thanks for answer to my topics.
>
>
I made one stored procedure that delete one table, but when
call/execute the procedure this show
>
SQL0532N A parent row cannot be deleted because the relationship
"TXN_TRANSACTION.FK_SCLI " restricts the deletion.
>
Then in the procedure it adds one delete of the foreign keys. This it
is the procedure
>
CREATE procedure eis.DeleteUpdate()
begin atomic
declare txtdrop varchar(1000);
declare txtadd varchar(1000);
>
SET txtdrop = 'ALTER TABLE EIS.CLI_CLIENT DROP CONSTRAINT
SQL051102111045710';
EXECUTE IMMEDIATE txtdrop;
>
>
FOR V1 AS
SELECT
B.CLIENTID AS IDCLIENTID,
B.MAPPEDCLIENTID AS MAPPED
FROM EIS.CLI_MAPING B
WHERE
STATUSID = 3 AND
CLIENTID != MAPPEDCLIENTID
DO
>
DELETE FROM EIS.CLI_BANK
WHERE CLIENTID = IDCLIENTID;
>
DELETE FROM EIS.CLI_CLIENT
WHERE CLIENTID = IDCLIENTID;
>
>
END FOR;
>
SET txtadd = 'ALTER TABLE EIS.CLI_CLIENT
ADD CONSTRAINT SQL051102111045710 PRIMARY KEY (CLIENTID)';
EXECUTE IMMEDIATE txtadd;
end
>
>
But when call this stored procedure show the following message
>
SQL0910N The SQL statement cannot access an object on which a
modification is
pending. SQLSTATE=57007
SQL0910N The SQL statement cannot access an object on which a
modification is pending.
>
What I really need with the procedure is that it allows me to delete
registries or rows of the table.


Greetings

Iván
Sep 7 '06 #4
Ivan wrote:
Hello to all and thanks for answer to my topics.
I made one stored procedure that delete one table, but when
call/execute the procedure this show

SQL0532N A parent row cannot be deleted because the relationship
"TXN_TRANSACTION.FK_SCLI " restricts the deletion.
Any particular reason why you are not using ON DELETE CASCADE for the
foreign key definition?

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Sep 8 '06 #5
I put commit as follow

SET txtdrop = 'ALTER TABLE EIS.CLI_CLIENT DROP CONSTRAINT
SQL051102111045710';
EXECUTE IMMEDIATE txtdrop;
COMMIT;

But show this message

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL20112N A SAVEPOINT cannot be set because a SAVEPOINT already exists
and
nested SAVEPOINTS are not supported. LINE NUMBER=9. SQLSTATE=3B002

If I use SAVEPOINTS does not leave me either

Greetings

Iván

jefftyzzer wrote:
Right. My reasoning is that under the explanation for the error you're
getting, it says (in part):

"The application program attempted to access an object within the
same unit of work in which either:
<SNIP>
The application program issued a statement against the object
that added or dropped a constraint."
<SNIP>

And under the user response section, it says (in part):

"Modify the application program so there is no attempt to access
an object within the same unit of work in which the modification
was made."

So, the issue surrounds units of work. If you've got autocommit turned
off (in which case you need to issue explicit COMMITs after DDL and DML
statements), then it sounds like you need to add a COMMIT after you do
the ALTER.

--Jeff

Ivan wrote:
Excuse me, to that you talk about with autocommit setting ?
jefftyzzer wrote:
Hi, Ivan:
>
OK--just dealing with the error you've reported (as opposed to talking
about your design/approach), it looks like you're dealing with the
second bullet-item under the help description for this error code
(execute "? SQL-0910N" in a command editor and you'll see what I mean).
Can you tell us what your autocommit setting is when executing the SP?
>
--Jeff
>
Ivan wrote:
Hello to all and thanks for answer to my topics.


I made one stored procedure that delete one table, but when
call/execute the procedure this show

SQL0532N A parent row cannot be deleted because the relationship
"TXN_TRANSACTION.FK_SCLI " restricts the deletion.

Then in the procedure it adds one delete of the foreign keys. This it
is the procedure

CREATE procedure eis.DeleteUpdate()
begin atomic
declare txtdrop varchar(1000);
declare txtadd varchar(1000);

SET txtdrop = 'ALTER TABLE EIS.CLI_CLIENT DROP CONSTRAINT
SQL051102111045710';
EXECUTE IMMEDIATE txtdrop;


FOR V1 AS
SELECT
B.CLIENTID AS IDCLIENTID,
B.MAPPEDCLIENTID AS MAPPED
FROM EIS.CLI_MAPING B
WHERE
STATUSID = 3 AND
CLIENTID != MAPPEDCLIENTID
DO

DELETE FROM EIS.CLI_BANK
WHERE CLIENTID = IDCLIENTID;

DELETE FROM EIS.CLI_CLIENT
WHERE CLIENTID = IDCLIENTID;


END FOR;

SET txtadd = 'ALTER TABLE EIS.CLI_CLIENT
ADD CONSTRAINT SQL051102111045710 PRIMARY KEY (CLIENTID)';
EXECUTE IMMEDIATE txtadd;
end


But when call this stored procedure show the following message

SQL0910N The SQL statement cannot access an object on which a
modification is
pending. SQLSTATE=57007
SQL0910N The SQL statement cannot access an object on which a
modification is pending.

What I really need with the procedure is that it allows me to delete
registries or rows of the table.


Greetings

Iván
Sep 8 '06 #6
Ivan wrote:
I put commit as follow

SET txtdrop = 'ALTER TABLE EIS.CLI_CLIENT DROP CONSTRAINT
SQL051102111045710';
EXECUTE IMMEDIATE txtdrop;
COMMIT;

But show this message

DB21034E The command was processed as an SQL statement because it was
not a
valid Command Line Processor command. During SQL processing it
returned:
SQL20112N A SAVEPOINT cannot be set because a SAVEPOINT already exists
and
nested SAVEPOINTS are not supported. LINE NUMBER=9. SQLSTATE=3B002

If I use SAVEPOINTS does not leave me either
That's because you stated BEGIN ATOMIC.You can't COMMIT inside of an
ATOMIC BLOCK. Conflicting request.
--
Serge Rielau
DB2 Solutions Development
IBM Toronto Lab

IOD Conference
http://www.ibm.com/software/data/ond...ness/conf2006/
Sep 9 '06 #7

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

Similar topics

0
by: Carlos Ibarra | last post by:
In various places I have seen mentioned the importance of indexing foreign keys to avoid table locks on the child table on parent update/delete and full table scans when the constraint has action...
0
by: Rainer Collet | last post by:
Hi! I have a question how to solve the folloing task: I have 2 tables referencing each over: An user table and an address table. Each user has one or no address. If an user is dropped the...
1
by: Vinodh Kumar P | last post by:
I understand the number of foreign keys allowed is restricted by the DBMS I use. In a general relational schema design perspective how many foreign keys a table shall have? If I have large number...
11
by: suma | last post by:
Hello, I want to delete duplicate rows in a table when no primary key is defined. For eg: If we have table1 with data as below, Suma 23 100 Suma 23 100 I want to delete a row from this...
0
by: unreal4u | last post by:
hi everybody .. first post ... hope someone answers it ... Well .. this is my problem ... I got 2 tables: /*==============================================================*/ /* Table:...
1
by: lundeman | last post by:
Hi list As I'm new to this list please kick me in the right direction if this question is better asked somewhere else. I'm seing some wird behavoure regarding foreign keys. My situation is...
10
by: D. Dante Lorenso | last post by:
I'd like to run a clean up command on my tables to eliminate rows that I'm no longer using in the database. I want to do something like this: DELETE FROM tablename WHERE...
1
by: Thomas T. Thai | last post by:
I'm looking for a better way to make use of foreign keys. Here is a sample setup: -- TESTING Foreign Keys create table mod ( mod_id int not null primary key, name varchar(32) not null...
6
by: bobdurie | last post by:
If i create a simple table with a foreign key constraint, does it create an implicit index on that given ID? I've been told this is done in some databases, but i need to know for sure if SQL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.