 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Prasad Kulkarni Guest
|
Posted: Tue Nov 11, 2003 5:09 am Post subject: Deletion of a record in self referenced table |
|
|
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
|
Posted: Tue Nov 11, 2003 9:26 am Post subject: Re: Deletion of a record in self referenced table |
|
|
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
|
Posted: Tue Nov 11, 2003 6:25 pm Post subject: Re: Deletion of a record in self referenced table |
|
|
"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 |
|
 |
|
|
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
|
|