Delete table in single shot!

jemmyjemmy Member Posts: 247
Hi folks,

Anyone knows how to delete table if there's existing data in its fields.
The manual we have to delete each field's data.
I require a fast way to accomplish this... please advice.

Thanks in advance as always.

Jemmy

Comments

  • jmjm Member Posts: 156
    Hi,

    what about:

    DELETEALL
    This function is used to delete all records that are selected by the filter settings – if no filters are set, all records in the table will be deleted.

    (Page 268 in Application Designer’s Guide, w1w1adg.pdf)

    br
    Josef Metz
    br
    Josef Metz
  • WarfoxWarfox Member Posts: 53
    Yes thats right but this will be betten in performance:
    repeat
      Table.delete;
    until Table.next = 0;
    
  • Luc_VanDyckLuc_VanDyck Member, Moderator, Administrator Posts: 3,633
    A DELETEALL instruction will be executed on the server, while a REPEAT ... DELETE ... UNTIL NEXT construction is executed on the client and every record needs to be retrieved from the server and send to the client.

    Therefore, DELETEALL is the way the go!
    No support using PM or e-mail - Please use this forum. BC TechDays 2024: 13 & 14 June 2024, Antwerp (Belgium)
  • jemmyjemmy Member Posts: 247
    Josef,
    Thanks buddy... that's exactly what I think but I forget where I know it earlier. Yeah, The Bible of Navision comes again.

    Warfox,
    Thanks!!! you are a great by the experiences. It's good that you know the better way to do these. Any reasons?

    Just edited "any reason"
    I think Luc has the answers...
    Thanks Luc for correcting us to the correct thinkings!!!


    Cheers,

    Jemmy
  • jmjm Member Posts: 156
    Hi Luc,

    i agree completely with you.

    @Warfox:
    Why do you think that REPEAT .. UNTIL will betten in performance?

    br
    Josef Metz
    br
    Josef Metz
  • pdjpdj Member Posts: 643
    If you wish to delete the entire content of a table, and even DELETEALL is to slow, then there is a dirty alternative... Use at own risk - I have only seen it used with the Native DB - however I think it works in SQL as well...
    Object.SETRANGE(Type,Object.Type::TableData);
    Object.SETRANGE("Company Name",COMPANYNAME);
    Object.SETRANGE(ID,DATABASE::"Customer Price Group"); // This is the table to flush
    Object.DELETEALL;
    
    But test it GOOD and use extreme caution before using this in production enviroment. (I have only seen and used it in internal tools) I don't know which permissions it requires...
    Regards
    Peter
  • jemmyjemmy Member Posts: 247
    A DELETEALL instruction will be executed on the server, while a REPEAT ... DELETE ... UNTIL NEXT construction is executed on the client and every record needs to be retrieved from the server and send to the client.

    All,

    I have a question based on quoted statement, how about if we do it in the server machine or at single user installation, which one is faster?
    Is still DELETEALL command? :-s

    Let me know your opinions...
  • Timo_LässerTimo_Lässer Member Posts: 481
    I've heared that the REPEAT..UNTIL variant should be faster on a SQL server. For native servers the DELETEALL is the fastest way.

    Myself has no experience with this performance.
    Timo Lässer
    Microsoft Dynamics NAV Developer since 1997
    MSDynamics.de - German Microsoft Dynamics Community - member of [clip]
  • eromeineromein Member Posts: 589
    I don't think we will see difference in performance, even if there is a difference.

    Maybe if you have millions and millions of records you could see a little difference. Maybe... (we need to test this).

    But still, would this be a reason to make a loop? Type the words REPEAT, UNTIL and record.NEXT = 0 to many just for that bit of performance?

    And I think a deleteall is MUCH easier to read that a loop.

    So.... let's go for that DELETEALL, let's go fot that Navision standard.
    "Real programmers don't comment their code.
    If it was hard to write, it should be hard to understand."
  • jemmyjemmy Member Posts: 247
    You are right!!!

    In my test:
    DELETEALL is faster than DELETE
    Navision 4.0
    SQL Option
    SQL 2000 SP#3
    Windows 2000 Adv.Server SP#4
    DB Server and client are located in single machine!
    Table has 100,000 records, 10 columns, I created a fake table haha.. :mrgreen:

    I haven't tried in the natives, are you curious? Hmm, anyways research is good... let's build the navision knowledge base...

    Regards,

    Jemmy
  • IngEolRuinIngEolRuin Member Posts: 23
    Only problem with the DELETALL is it locks the client.
    I personally dislike "long" Application doesnt respond windows.

    The idea deleting the tabledata is also nice, but I dont dare to think what happens if THAT transaction crashes ...
    =(there is no question that cannot be used if we use our brain)=
  • themavethemave Member Posts: 1,058
    I bet this is just as fast,

    open object designer, click on table, select run

    I click on the top corner, select all, press delete

    it is faster because I don't have to write a program and code it, (which I don't have the license for anyways)



    just kidding with you. I'm sure with a big table it would take a while to select all the records.
  • ara3nara3n Member Posts: 9,258
    Actually running a table and selecting all and click on delete will run slower if there is code on the triger ondelete. Navision will then delete one record at a time and run the underlying code. Deleteall will not run the underlying code. Deleteall(true) will.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • philippegirodphilippegirod Member Posts: 191
    And if you use many filters, don't forget to use the right key, it is incredibly faster with the right key...
    My candle burns by both ends, it will not last the night,
    But oh my foes and oh my friends, it gives a lovely light
  • girish.joshigirish.joshi Member Posts: 407
    Warfox's deleteall comment was the first instance of flame bait I've seen on mibuso.

    Let me be the first to take it for what it was and say

    WTF???????
  • DenSterDenSter Member Posts: 8,307
    flamebait? what are you talking about?
  • utouto Member Posts: 36
    pdj wrote:
    If you wish to delete the entire content of a table, and even DELETEALL is to slow, then there is a dirty alternative... Use at own risk - I have only seen it used with the Native DB - however I think it works in SQL as well...
    Object.SETRANGE(Type,Object.Type::TableData);
    Object.SETRANGE("Company Name",COMPANYNAME);
    Object.SETRANGE(ID,DATABASE::"Customer Price Group"); // This is the table to flush
    Object.DELETEALL;
    
    But test it GOOD and use extreme caution before using this in production enviroment. (I have only seen and used it in internal tools) I don't know which permissions it requires...

    For SQL option, it's works properly. But you must have the authorization to delete coz permission property in report cannt work. And now I'm looking the way to delete data by unauthorized user.
Sign In or Register to comment.