BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Deletion of a record in self referenced table

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
Prasad Kulkarni
Guest





PostPosted: Tue Nov 11, 2003 5:09 am    Post subject: Deletion of a record in self referenced table Reply with quote



Hello All,

I have a self referenced table with structure like
Num Integer
Text String
Level Integer
Parent Integer linked to Num

Now if a parent record is deleted i have to delete all its children,
children's children....etc. Is there any simple way to do this.

Regards
Prasad
Back to top
Jeremy Collins
Guest





PostPosted: Tue Nov 11, 2003 9:26 am    Post subject: Re: Deletion of a record in self referenced table Reply with quote



Prasad Kulkarni wrote:
Quote:
Hello All,

I have a self referenced table with structure like
Num Integer
Text String
Level Integer
Parent Integer linked to Num

Now if a parent record is deleted i have to delete all its children,
children's children....etc. Is there any simple way to do this.

Your database engine might be able to do this using referential
integrity, so if you set up your primary and foreign keys
correctly this will happen automatically.

If not, store the NUM in the dataset's BeforeDelete event,
and in the AfterDelete event execute an SQL statement to remove
the orphans:

DELETE FROM tb_tree WHERE Parent = NUM_VALUE

You will find future maintenance easier if you use more descriptive
field names (ITEM_ID, ITEM_TEXT for example). And isn't "LEVEL"
redundant?


--
jc

Remove the -not from email


Back to top
Bruce Roberts
Guest





PostPosted: Tue Nov 11, 2003 6:25 pm    Post subject: Re: Deletion of a record in self referenced table Reply with quote




"Jeremy Collins" <jd.collins (AT) ntlworld-not (DOT) com> wrote


Quote:
If not, store the NUM in the dataset's BeforeDelete event,
and in the AfterDelete event execute an SQL statement to remove
the orphans:

One might want to remove the children before removing the parent. This way
if child removal fails for some reason one doesn't end up with invalid
references.



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.