Skip to main content
1 of 2
Hannah Vernon
  • 70.5k
  • 22
  • 177
  • 321

Generate new sequential GUIDs on the client end. This will reduce the frequency of page splits to a more manageable level.

In C# on Windows, the following will generate 100 sequential UUID values:

using System;
using System.Runtime.InteropServices;

namespace GUIDtest
{
    class Program
    {
        [DllImport("rpcrt4.dll", SetLastError = true)]
        static extern int UuidCreateSequential(out System.Guid guid);

        static void Main(string[] args)
        {
            Guid guid; ;
            for(var a = 0; a < 100; a++)
            {
                _ = UuidCreateSequential(out guid);

                Console.WriteLine($"guid: {guid}");
            }
        }
    }
}

Note that for cases where the security of the generated guid is not of paramount importance it's ok to generate GUIDs using this methodology since they are still going to be for all intents-and-purposes unique. This method uses the MAC address of the computer running the code to generate a portion of the address, thus guaranteeing its uniqueness. The one gotcha here would be ensure you aren't running this code in multiple virtual machines configured to use the same MAC addresses (they would need to be on different networks for that to even work, so this is unlikely to be a problem).

Hannah Vernon
  • 70.5k
  • 22
  • 177
  • 321