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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Delete top 1000 records from table

(1) ShareShare
ReportReport
Posted on by 6,478

Hi,

is it possible to delete top 1000 (FirstOnly1000?) records from table? If yes, what is best code to use?

While select firstOnly1000? or I can somehow use delete_from too?

Thanks.

*This post is locked for comments

I have the same question (0)
  • André Arnaud de Calavon Profile Picture
    300,911 Super User 2025 Season 2 on at

    Hi JOni,

    Delete_from is not working here as you can only add some ranges. I wonder what would be the background of your question. For now, I would say a while select would help you, but might be slow...

    If it is possible with SQL, you could consider using the Sstatement / Connection classes to execute a SQL statement directly from AX.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at

    RecId blocks are almost sequential, you may try that, but it is not guaranteed it will be exactly 1000 records at all. Fetch first record by your ordering criteria, get RecId, add 1000, then call the set-based delete operation on it where RecId >= yourstoredRecId and <= yourstoredRecId+1000.

    Since RecId is an index most of the times as well in a table, doing a range for it with a delete recordset block could be fast as well.

  • Erik HB Profile Picture
    205 on at

    The easiest (but slowest) option would be to do it in a loop, delete one record at a time and increase a counter every time.  When the counter reaches 1000 or if there are no more records left, you break out of the loop.

    In AX2012, up to and including R3, you may get a performance improvement depending on your table and whether the delete() method has been overridden, if you first determine the RecIds you want to delete, stuff them into a temporary table (TempDB type) and then do a delete_from on your table, joined to that temporary table.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans