Options

Delete Entries on 3 Tables at Same Time

elToritoelTorito Member Posts: 191
Hi,

i have 3 Tables....

1. Table has Key: Name
2. Table has Key: Name, Subname
Subname
3. Table has Key, Name, Subname, LineNo


When i delete Data from Table 1 i would that all Datarows in Table 2 that have the same Name will too deleted and delete all Datarows in Table 3 what have the Same Name and Subname was deleted in Table 2.

For Example:

Table1
Name Desription
Mercedes German Car
Peugeot French Car

Table2:
Name Subname
Mercedes C-Class
Mercedes A-Class
Mercedes S-Class
Peugeot 206CC
Peugeot 306cc
Peugeot 106


Table3:
Name Subname LineNo Colour
Mercedes C-Class 10000 red
Mercedes A-Class 10000 red
Mercedes A-Class 20000 green
Mercedes S-Class 10000 blue
Peugeot 206CC 10000 black
Peugeot 206CC 20000 yellow
Peugeot 306cc 10000 white
Peugeot 106 10000 pink


When I Delete from Table1 the Data with Name Mercedes, it must be delete follow data from Table2:
Mercedes C-Class
Mercedes A-Class
Mercedes S-Class

And Follow Data from Table 3:
Mercedes C-Class 10000 red
Mercedes A-Class 10000 red
Mercedes A-Class 20000 green
Mercedes S-Class 10000 blue


Then when in Table 2 i delete the datarow "Mercedes C-Class"
It must delete from Table3 follow Datarows:
Mercedes C-Class 10000 red


My Problem is that when i start the onDelete Trigger in Table1 , that it only deletes this datarow, and when it was deleted i don't know keys for delete Data in Table2.

Or must i put this Function in a Form for delete the data from the other tables ? Perhaps in OnDeleteRecord Trigger ?

I Hope you understand what i mean and can help me giving some tipps.

Thanks.

PS:
Code in Table1:
onDelete()
recTable2.SETRANGE(Name,Name);
IF recTable2.FIND('-') THEN
    recTable2.DELETEALL(TRUE);

Code in Table2:
onDelete()
recTable3.SETRANGE(Name, Name);
recTable3.SETRANGE(Subname, Subname);
IF recTable3.FIND('-') THEN
   recTable3.DELETEALL(FALSE);

THANKS AGAIN
(Oo)=*=(oO)

Comments

  • Options
    kinekine Member Posts: 12,562
    You must have code in OnDelete trigger to be able to cascade the delete to another tables...
    Code in Table1:
    onDelete()
    Code:
    
    recTable2.SETRANGE(Name,Name);
    recTable2.DELETEALL(TRUE);
    
    
    Code in Table2:
    onDelete()
    Code:
    
    recTable3.SETRANGE(Name, Name);
    recTable3.SETRANGE(Subname, Subname);
    recTable3.DELETEALL(TRUE);
    
    

    This code seems OK for me...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    elToritoelTorito Member Posts: 191
    I Have this Code in the OnDelete Triggers ,...
    But when i want to delete one Row from the first table it says me that the row of Table2 can't find it ...

    But the Row exists with the expected Keys ... :-k
    (Oo)=*=(oO)
  • Options
    kinekine Member Posts: 12,562
    And what you have in OnDelete trigger on Table2? :whistle:
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    elToritoelTorito Member Posts: 191
    kine wrote:
    And what you have in OnDelete trigger on Table2? :whistle:

    in Table2
    OnDelete()
    recTable3.SETRANGE(Name, Name);
    recTable3.SETRANGE(Subname,Subname);
    recTable3.DELETEALL(TRUE);
    


    When i would delete Row in table 2 the Error Message what came is:

    Entry not found Keys expected:
    Name = "Name"
    Subname = "Subname"
    LineNo = 10000


    But in Table3 exists a Row with this Values.
    (Oo)=*=(oO)
  • Options
    kinekine Member Posts: 12,562
    if recTable3 is global variable, use recTable3.RESET to be sure, that there is no left filter before...

    And what you have in table3 in ondelete?
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Options
    elToritoelTorito Member Posts: 191
    kine wrote:
    if recTable3 is global variable, use recTable3.RESET to be sure, that there is no left filter before...
    And what you have in table3 in ondelete?

    :oops: :oops: :oops: :oops:

    In onDelete() in Table3 i had a Funktion what Sorts me any rows after delete one , and in this function i was set a filter for counting and sorting my entries.

    When i Comment Out this function, it works nice delete all entries, i think that i put my sort function in the onDelte Trigger in the Form, then it must be okay.
    (Oo)=*=(oO)
Sign In or Register to comment.