Datatype: uniqueidentifier or bigint as primarykey?

Posted on 2008-11-04
Last Modified: 2013-11-11
Uniqueidentifier or bigint as primarykey? Which is better to use as a primary key?

Using uniqueidentifier you will be given a global uniqueidentifier
but this also means the value will be very large! larger than bigint!
16 bytes vs 4 bytes!!!

is it really important?
Question by:Khou
    LVL 14

    Accepted Solution

    LVL 27

    Assisted Solution

    I dont think it makes any considerable difference, as long as you dont have a composite primary key.
    LVL 7

    Assisted Solution

    From my point of view, it makes difference for  large tables.
    Redundant 12 bytes could be at cost, because as PK it will involved in all seek operations.

    Another reason: you cannot make guid autoincrement (by IDENTITY(1,1)).

    The only huge benefit of guid is really multy-server environment, to provide uniqueness.

    LVL 22

    Assisted Solution

    Depends what you are going to use it for. You haven't given us much clue because "primary key" actually says very little about how it will be used. Do you mean that you intend to use it only as a surrogate key?

    Author Comment

    " Do you mean that you intend to use it only as a surrogate key?"


    At the end of the day, I decided to Unquieidentifier , with newsequecialid().

    Reason: GUID for replication, newsequeicailid() for performance.
    still not as fast as int, but will do.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
    SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
    This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
    This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now