Search code examples
sql-serverprimary-key-design

Why does a database have a weird alphanumeric key


I am trying to connect data in two databases, both created automatically by a different UI application. In one, all the keys are in this format "D8FC23D7-97D6-42F5-A52F-1CE93087B3A4".

Is there any reason this would be done? I also saw keys that look similar in a GIS database. I can't tell if these are supposed to be some computed key, maybe to detect what I am trying to do, or just random with some other intent.

PS I am using SQL Server. From what I can gather, this is not something that would be auto generated by SQL Server.


Solution

  • This is a GUID, also called UUID, a universally unique identifier (confer, for example, wikipedia or rfc4122). The idea behind a guid is that applications can generate identifiers, that are globally unique, without the need of a central unit doing any choreography (see motivation from rfc4122 below).

    Various systems, databases, and programming languages offer functionality for generating UUIDs (e.g. SELECT NEWID() in sql server); the benefit is that with UUID generators, application can generate globally identified units in autarkical manner.

    UUIDs can serve as database keys, though in most cases you will find much more lightweight and much more proper keys.

    One of the main reasons for using UUIDs is that no centralized
    authority is required to administer them (although one format uses
    IEEE 802 node identifiers, others do not). As a result, generation
    on demand can be completely automated, and used for a variety of
    purposes. The UUID generation algorithm described here supports very high allocation rates of up to 10 million per second per machine if
    necessary, so that they could even be used as transaction IDs.

    UUIDs are of a fixed size (128 bits) which is reasonably small
    compared to other alternatives. This lends itself well to sorting,
    ordering, and hashing of all sorts, storing in databases, simple
    allocation, and ease of programming in general.

    Since UUIDs are unique and persistent, they make excellent Uniform Resource Names. The unique ability to generate a new UUID without a
    registration process allows for UUIDs to be one of the URNs with the
    lowest minting cost.