UUID Vs Primary Key

Manish Goyal

Manish Goyal

@manish-r2Hoep Oct 22, 2024
Yesterday i was working on some project and my boss asked me to implement UUID in database instead of primary key
I was not aware of uuid so i searched on google about uuid and i found an intersting quote from wikipedia
".. after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%."

I read since it is based on timestamp ,hence it is almost impossible to generate duplicate uuid, then i thought if it really so , then why i don't know about uuid till now? I don't even read about it in my engineering books . Why we don't use it as it can reduce many concurrency problems in database ?

If anyone knows about it then please share

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Jul 23, 2011

    Version 5 UUIDs use a scheme with SHA-1 hashing - This is something like gives a promise that it won't be duplicated right?
  • gaurav.bhorkar

    gaurav.bhorkar

    @gauravbhorkar-Pf9kZD Jul 24, 2011

    Guid's are 128 bit long, may be that is the reason we don't use them as primary keys for unnecessary space occupied. An auto incremented counter mostly solves our problem of a primary key in most of the databases.
  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Jul 24, 2011

    For space constraints you gotta use PK only... 😔
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Jul 25, 2011

    gaurav.bhorkar
    Guid's are 128 bit long, may be that is the reason we don't use them as primary keys for unnecessary space occupied. An auto incremented counter mostly solves our problem of a primary key in most of the databases.
    May be it occupies large space ,but it also solves concurrency problem
  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Jul 25, 2011

    What if there are two same UUID... The probability is less, but it is possible!!! 😲
  • Manish Goyal

    Manish Goyal

    @manish-r2Hoep Jul 25, 2011

    praveenscience
    What if there are two same UUID... The probability is less, but it is possible!!! 😲
    UPTO i have read about it on net ,
    It is based on timestamp value , so there are very less chance that there will be same uuid , at least for next 25 years
  • PraveenKumar Purushothaman

    PraveenKumar Purushothaman

    @praveenkumar-66Ze92 Jul 25, 2011

    I meant the theoretical stuff dude... Yeah, 25 years is there... 😀