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 :
Microsoft Dynamics AX (Archived)

Delete top 1000 records from table

(1) ShareShare
ReportReport
Posted on by 6,480

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
    303,730 Super User 2026 Season 1 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

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans