>Hello
>
>I have a hierarchical table, containing ID and ParentID fields. I have created a self-join on these two fields, then I have created a RI rule (using RI builder), that deletes the subordinate records when a parent record is deleted.
>
>I was surprised to find that this doesn't work. Instead I get a "Trigger failed" message. Now follows the question: Is there any way (beside recursive scanning) to delete all the subordinated records (and theirs subordinate records, and so on) when I delete a parent record?
>
>Thanks.
It seems to me you should use recurrent function:
=deletechilds(mytable.id)
delete in mytable
Function deletechilds
lParameter nParentid
local cAlias
cAlias=gettempalias()
use (dbf('mytable')) in 0 again alias &cAlias.
select (cAlias)
set order to tag parentid
seek nParentid
scan while eval(cAlias+'.parentid')=nParentid
=deletechilds(eval(cAlias+'.id'))
delete in &cAlias.
endscan
use in &cAlias.
endfunc
PS: it is not tested.
Edward Pikman
Independent Consultant