Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Best way to delete large amount of records

Posted on by 6,414

Hi,

We have some duplicated records in LogisticsAddresssCity table (Some cities are inserted several thousand times) and we need to clear them up and only keep cities which has one specific customized field filled.

Before deletion we do the update of zip codes with correct record from city.

Which is best to use? "Delete_from" or "while select" and should I foresee something else?

Thanks.

*This post is locked for comments

  • Johnny Profile Picture
    Johnny 6,414 on at
    RE: Best way to delete large amount of records

    Hi Martin,

    thanks for suggestions.

    That's the mistake done probably during the data migration or zip code upload. Indeed city should be divided to many zip codes, but something has happened and now we have for each zip code the record in city table. e.g. zip1, zip2, zip3 should be related to city1, but we have three records for city1 in table and it's a mistake.

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Best way to delete large amount of records

    @Joni: If you used the same SQL code as generated for the delete_from statement, how could it be faster? It would be identical. Another topic would be if you found an optimization that can be only written in SQL and not in X++, but you didn't mention anything like that. And if you bypass AX business logic and use a direct SQL statement, it's easy to make some mistake (e.g. forgetting about a delete action) and end up with corrupted data consistency.

    By the way, I wonder which country has exactly one zip code for each city (1:n). Usually one city is divided to many zip codes (1:n).

  • sureshch Profile Picture
    sureshch 20 on at
    RE: Best way to delete large amount of records

    If you want to delete only the records in this table not in related table you can use sql delete statement with your customized field value in where condition

    Thanks

  • Suggested answer
    Ajit Profile Picture
    Ajit 8,755 on at
    RE: Best way to delete large amount of records

    Deleting from SQL would be much faster but we should take care of related records as well. In your case it looks like straight forward. You want to delete records from LogisticsAddressCity table where custom column is blank, Right? You would have to update the LogisticsAddressZipCode table with correct city recid.

  • Johnny Profile Picture
    Johnny 6,414 on at
    RE: Best way to delete large amount of records

    Thanks for replies.

    What I'm thinking is maybe it's better to be done directly in SQL.

    The data that should be deleted is around 900.000 records.

    First there should be update of zip code table (there is 1:1 relation between zip codes and cities and not 1:N). I think this happened during data migration for each zip code new record in city table where inserted (wrong).

    Also, LogisticsPostalAddress table should be updated and after it we need to delete duplicated records from cities. It means that we are working with millions of records.

    What would you suggest?

    Thanks.

  • Martin Dráb Profile Picture
    Martin Dráb 230,188 Most Valuable Professional on at
    RE: Best way to delete large amount of records

    You can rephrase it to "is it faster to send a single DELETE FROM command to database (assuming you know how to define the WHERE condition) or first fetching all the data from database and then delete them one by one?". It's obvious that delete_from will be many times faster. Just make sure that there isn't anything that would force AX to fall back to row-by-row processing.

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Best way to delete large amount of records

    Delete_from, if you want to delete the all table, or use conditions if you want to delete only some records.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans