what is uniqueidentifier in sql how it will work

  • Hi Friends,

    Any one can tell me what is uniqieidentifier ? where we use this?

    Thanks,

    Sandeep.

  • uniqueidentifier is a data type.

    BOL

    Merge replication and transactional replication with updating subscriptions use uniqueidentifier columns to guarantee that rows are uniquely identified across multiple copies of the table.

  • Is it an interview question?

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • To answer when you should use it...I would avoid it unless there is a legitimate reason to use it. Often it gets used as a primary key which causes performance issues due to fragmentation of indexes and pages. Additionally it is just simply a PITA to work with. It is really hard to type one manually and get it right. And although the type is uniqueidentifier it is possible to get duplicates, although the probability of this is incredibly small. Best to just not use them when there is a different option.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Sean Lange (3/8/2012)


    To answer when you should use it...I would avoid it unless there is a legitimate reason to use it. Often it gets used as a primary key which causes performance issues due to fragmentation of indexes and pages. Additionally it is just simply a PITA to work with. It is really hard to type one manually and get it right. And although the type is uniqueidentifier it is possible to get duplicates, although the probability of this is incredibly small. Best to just not use them when there is a different option.

    I couldn't have said it any better.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Hi,

    Generally Uniqueidentifier is a 36 bit alphanumeric unique Value that will not be duplicated.

    Its syntax is XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.

    It is a data type in SQLServer & it will be mostly used as Primary Key.

  • ard5karthick (3/12/2012)


    Hi,

    Generally Uniqueidentifier is a 36 bit alphanumeric unique Value that will not be duplicated.

    Its syntax is XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.

    It is a data type in SQLServer & it will be mostly used as Primary Key.

    Uniqueidentifier is a 16-byte binary values that operates as globally unique identifiers (GUIDs). The main use for a GUID is for assigning an identifier that must be unique in a network that has many computers at many sites.

    There is no such things as syntax for datatypes... It's like saying, that a Datetime has a syntax of DD MMM YYYY HH:MM:SS:mmm 🙂

    This data type in SQLServer used as Primary Key, mostly by people who has no idea of what they are doing or ones who forced to do it by above people.

    I do use this datatype mainly when I need to store something "very technical" for the application: For example: operation handle/key issued by the app which can be used for transactions grouping...

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

  • It has a Constant Format in which it will appear,

    And it is 36 Bit not 16 Bit and Each Digits can be of HexaDecimal Value From (0 -9) and (A- F)

    For more Info refer the below Link,

    http://msdn.microsoft.com/en-us/library/ms187942.aspx

  • ard5karthick (3/12/2012)


    It has a Constant Format in which it will appear,

    And it is 36 Bit not 16 Bit and Each Digits can be of HexaDecimal Value From (0 -9) and (A- F)

    For more Info refer the below Link,

    http://msdn.microsoft.com/en-us/library/ms187942.aspx%5B/quote%5D

    And the first line of this article...

    Is a 16-byte GUID.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • ard5karthick (3/12/2012)


    It has a Constant Format in which it will appear,

    And it is 36 Bit not 16 Bit and Each Digits can be of HexaDecimal Value From (0 -9) and (A- F)

    For more Info refer the below Link,

    http://msdn.microsoft.com/en-us/library/ms187942.aspx%5B/quote%5D

    Format is not a syntax, actually its appearance also depends on a client, it may appear with or without curved brackets...

    And about 32 vs 16 Bit - you can see in the previous post and at the article you refer to yourself. If you like to measure it in Bits, it won't be 16 nor 32 but 128 Bits (1 Byte - 8 Bits) :hehe:

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]

Viewing 10 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic. Login to reply