web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

delete records from the very heavy table

(0) ShareShare
ReportReport
Posted on by 1,271

Hello,

I need to delete records from the table which contains more than 24 million records. I need to delete them based on the created date time field. I used delete_record and there is an index on the filed  "created date time" but anyway it takes too much time. I checked then in SQL management studio that it doesn't fall to record level deleting row by row. It is still delete_from command on the SQL server and doesn't turn into while select{delete}is there any chance to somehow delete records using order by and only first 10 thousand using AX?

Or I need to write direct SQL statement?

something like this

WITH MyCTE AS (
    SELECT TOP (10) * 
    FROM SalesOrderDetail
    ORDER BY SalesOrderID DESC)
DELETE FROM MyCTE;

thanks.

I have the same question (0)
  • Verified answer
    Sergei Minozhenko Profile Picture
    23,095 on at

    Hi Azat,

    If it's a one-time operation, it's fine to do it directly in SQL with CTE statement.

    In x you can try to implement a day by day while loop and delete only one day per delete_from statement, it will decrease transaction time per delete statement, but it will not perform faster.

    TransDate deleteToDate = ...;
    
    select minof(CreatedDateTime)
        from salesOrderTable;
        
    TransDate startDate = salesOrderTable.CreatedDateTime   1; //Add one day
    
    while (startDate <= deleteToDate)
    {
        delete_from salesOrderTable
            where salesOrderTable.CreatedDateTime < startDate;
            
        startDate  ;
    }

    Another way is to use temp table to keep RecIds to be deleted and then use it as exist join table in the delete_from table statement. But if I remember correctly tempDB temp tables are not supported in AX2009

  • dark_knight Profile Picture
    1,271 on at

    thanks. I will do something out of two above.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Giorgio Bonacorsi Profile Picture

Giorgio Bonacorsi 694

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 646 Super User 2026 Season 1

#3
CP04-islander Profile Picture

CP04-islander 337

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans