Unix Technical Forum

Regarding Delete Restrict

This is a discussion on Regarding Delete Restrict within the DB2 forums, part of the Database Server Software category; --> Hi, I am doing a purge process and trying to delete rows .Let me know how efficiently I can ...


Go Back   Unix Technical Forum > Database Server Software > DB2

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 06:18 AM
razheev
 
Posts: n/a
Default Regarding Delete Restrict

Hi,
I am doing a purge process and trying to delete rows .Let me know how
efficiently I can handle the purge process because of the RI on the
tables.
TABLE A is a PARENT of TABLE B, TABLE C, TABLE D. I want to purge
rows from all the tables TABLE A (Parent), TABLE B (Child), TABLE C
(Child) and TABLE D (Child).
All these tables have DELETE RESTRICT . I dont want to have the orphans
in the table.
I dont want to have the child row exist without a parent. I thought of
purging the data starting by identifying what rows need to be purged
from the PARENT and delete from the CHILD.
Is this a good approach or Is there a better way so that Performance
will not be problem too.
Let me know
Thanks

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2008, 06:18 AM
razheev
 
Posts: n/a
Default Re: Regarding Delete Restrict

Actually it is like TABLE B is a CHILD of TABLE A, TABLE A1, TABLE A2.
(1 CHILD with Many PARENTS)
I need to purge rows from all the Parent and Child.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2008, 06:19 AM
Knut Stolze
 
Posts: n/a
Default Re: Regarding Delete Restrict

razheev wrote:

> Hi,
> I am doing a purge process and trying to delete rows .Let me know how
> efficiently I can handle the purge process because of the RI on the
> tables.
> TABLE A is a PARENT of TABLE B, TABLE C, TABLE D. I want to purge
> rows from all the tables TABLE A (Parent), TABLE B (Child), TABLE C
> (Child) and TABLE D (Child).
> All these tables have DELETE RESTRICT . I dont want to have the orphans
> in the table.
> I dont want to have the child row exist without a parent. I thought of
> purging the data starting by identifying what rows need to be purged
> from the PARENT and delete from the CHILD.
> Is this a good approach or Is there a better way so that Performance
> will not be problem too.


Do you want to delete all the rows from the tables you mentioned? If the
answer is yes, simply truncate all tables, possibly starting at D, which
has no further dependencies.

--
Knut Stolze
DB2 Information Integration Development
IBM Germany
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2008, 06:19 AM
Phil Sherman
 
Posts: n/a
Default Re: Regarding Delete Restrict

Have you really thought this out? with A, A1, A2 as parents of a common
child, what happens to other children of the parents when you go to
delete a row from the parent? Foreign keys on B mean that each of the
A(n) tables is expected to have rows with values that don't match a row
in the B table.

If each of the A(n) tables can have at most one child, then you will
have to read to B table rows to get the A(n) table values to identify
rows to delete.

Your RESTRICT rule in the foreign key definitions of table B will
prevent deleting rows from the A(n) tables as long as there is an
existing B row. You'll have to delete the B table row first, then the
matching rows from the parents.

I'd try to use an updatable cursor to retrieve the B table rows, then
use a positioned delete to delete the B table row. Use the data values
from the retrieval to delete the other parent rows.

Phil Sherman


razheev wrote:
> Actually it is like TABLE B is a CHILD of TABLE A, TABLE A1, TABLE A2.
> (1 CHILD with Many PARENTS)
> I need to purge rows from all the Parent and Child.
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:17 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com