AG UUID

UUID as a database primary key

The pros and cons of using a UUID as a primary key, and choosing between v4 and v7.

Advantages

You can mint IDs in the application ahead of time, merge multiple databases or shards without collisions, and avoid exposing the record count the way sequential integers do.

Drawbacks of v4

A random v4 is inserted at random positions in the index, which can cause page splits and cache inefficiency. On write-heavy tables this can lead to degraded performance.

v7 recommended

v7 increases chronologically and is inserted sequentially at the end of the index, mitigating v4's drawbacks. Consider v7 first as the primary key for newly designed tables.