Guid.CreateSequentialGuid in AL

This feature is simulating and also similar (not the same) to what the SQL NEWSEQUENTIALID does in order to generate consecutive GUIDs. See more on:

NEWSEQUENTIALID (Transact-SQL) – SQL Server | Microsoft Learn

This command is available since SQL Server 2005 (version 9.0). So the first question comes natural (why they took so long… NAAA… Kidding), is this SQL command used?

Nope.

And for good reason. If you want to create a new sequential GUID, you do not want to get into SQL, run a statement to get the GUID, get it back and issue another query with the GUID as parameter. NO WAY. Too many roundtrips.

And if you look at the documentation mentioned before…

See more: https://learn.microsoft.com/en-us/windows/win32/api/rpcdce/nf-rpcdce-uuidcreatesequential

This means that the sequential GUID will be created at NST level (in the middle tier) – no useless roundtrip to SQL – hence influenced where the session that is requesting the generation is connected…

Ahhh that’s too Nerdy, back to earth and let’s go straight to the point. Like Cate’s “Forget everything”…

Dynamics 365 Business Central 2025 Wave 2 has this brand new AL Statement Guid.CreateSequentialGuid that make better use of GUID in terms of performance. See below a usage example:

In this way, indexes are reduced in fragmentation compared to randomly generated GUIDs (the old AL CreateGuid – that is based on uuidcreate -).

As usual, to demonstrate how it works and looks like, just run the “Sequential GUID Demo” from the Demo app that you can download here:

https://github.com/duiliotacconi/DT.AL/tree/main/BC27-Performance-Features

and enter a discrete number of records to be created in a test table whose Primary Key (PK) is a GUID. I fully understand that in real-life scenario you rarely have a GUID PK but, instead, you might have a sort of systemId of your own. This example is just to showcase the concept.

Back to the example, try with e.g. 500.000 Records (peanuts…) as shown below:

NOTE: do not take duration numbers as written in the stone. The key benefits are under the sun and mainly related to reduced page splits and lower fragmentation of indexes, even tough generation of sequential GUIDs tends to be slightly faster than the legacy one.

And this will be the output, to show the format of GUIDs, that will be very similar.

You might notice that sequential GUIDs are very similar (but not the same) between each other and they will be placed contiguous during I/O activities hence improving performance in writing, reading and maintenance.

CONSIDERATIONS

With more and more APIs developed and used by humans or AI Agents through MCP servers, GUID is more and more frequent in a table definition (it is used “a granella” – as we used to say in Italy -) and what it seems just a maquillage addition to the AL portfolio, in the overall economy of resources should be a good and simple habit to new or existing (refactoring) implementations.

Translated into pure AL and your own go-dos: just substitute everywhere (even find and replace will work) the old CreateGuid() with the new shiny CreateSequentialGuid() and you will have a more performant handling of Global Unique IDentifier in your apps.

Over and Out.

Smart move from Product Group and a simple uptake for developers. And I love when I could say simple. No harms, no nothing. Just implement this new or refactoring pattern whenever there is the need of creating a GUID.

You (and the tsunami of Agents that soon will come) can thank me later…

Leave a comment

Blog at WordPress.com.

Up ↑