uniqueidentifier Type

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qhjghz
    New Member
    • Aug 2007
    • 26

    uniqueidentifier Type

    Hi all, need some help. I have a table called my_table say, and there is a uniqueidentifie r field in that table say my_column.
    When I execute this query, I get back a row

    select * from my_table where
    my_column = 'B844EC98-F509-4F41-BC42-301DD22F6A12'

    But, when I change the string value by changing any of the characters, I get an error stating

    Server: Msg 8169, Level 16, State 2, Line 1
    Syntax error converting from a character string to uniqueidentifie r.


    However, if I change any of the numbers in the string, I do not get any data, but also I get no errors.
    Can anyone please explain why this happens? Is it so, that for uniqueidentifie r columns, there are only a fixed set of characters, but numbers may alter? I am new to SQL Server, so it will be great if someone helps me out(I have replaced one character by those characters which are already present in the string itself, I don't get any errors. But suppose I replace D by X, I get an error)
  • azimmer
    Recognized Expert New Member
    • Jul 2007
    • 200

    #2
    Originally posted by qhjghz
    Hi all, need some help. I have a table called my_table say, and there is a uniqueidentifie r field in that table say my_column.
    When I execute this query, I get back a row

    select * from my_table where
    my_column = 'B844EC98-F509-4F41-BC42-301DD22F6A12'

    But, when I change the string value by changing any of the characters, I get an error stating

    Server: Msg 8169, Level 16, State 2, Line 1
    Syntax error converting from a character string to uniqueidentifie r.


    However, if I change any of the numbers in the string, I do not get any data, but also I get no errors.
    Can anyone please explain why this happens? Is it so, that for uniqueidentifie r columns, there are only a fixed set of characters, but numbers may alter? I am new to SQL Server, so it will be great if someone helps me out(I have replaced one character by those characters which are already present in the string itself, I don't get any errors. But suppose I replace D by X, I get an error)
    IMHO it's best to treat uniqueidentifie rs SQL Server internal structures which you do not want to manipulate by hand like that. They are usually assigned to column automatically (by setting the default to the newid() function), and one usually uses them to select a specific row (or rows) -- usually in joins, sometimes in other operations (esp. DELETE). If I were you I wouldn't want to make out the internals of uniqueidentifie rs unless there's absolutely no other way.
    If you do want to play around with it keep in mind: each position is a hex digit, so valid letters are 'A'..'F' only.

    Comment

    • almaz
      Recognized Expert New Member
      • Dec 2006
      • 168

      #3
      Originally posted by qhjghz
      However, if I change any of the numbers in the string, I do not get any data, but also I get no errors.
      Can anyone please explain why this happens? Is it so, that for uniqueidentifie r columns, there are only a fixed set of characters, but numbers may alter? I am new to SQL Server, so it will be great if someone helps me out(I have replaced one character by those characters which are already present in the string itself, I don't get any errors. But suppose I replace D by X, I get an error)
      Uniqueidentifie r type (also called GUID, "Globally Unique IDentifier") have a standard text representation of "8chars-4chars-4chars-4chars-12chars", where each character is a hexadecimal digit (0-9, A-F). See GUID for more information.

      Comment

      • qhjghz
        New Member
        • Aug 2007
        • 26

        #4
        Originally posted by azimmer
        IMHO it's best to treat uniqueidentifie rs SQL Server internal structures which you do not want to manipulate by hand like that. They are usually assigned to column automatically (by setting the default to the newid() function), and one usually uses them to select a specific row (or rows) -- usually in joins, sometimes in other operations (esp. DELETE). If I were you I wouldn't want to make out the internals of uniqueidentifie rs unless there's absolutely no other way.
        If you do want to play around with it keep in mind: each position is a hex digit, so valid letters are 'A'..'F' only.

        "If you do want to play around with it keep in mind: each position is a hex digit, so valid letters are 'A'..'F' only" That's the answer I was looking for. Thanks a lot. That is the reason why when I try to substitute "b" BY "X", it does not work, but when I replace it by "A", it works

        Comment

        Working...