Home All Groups Group Topic Archive Search About

Uniqueidentifier GUID question

Author
28 Jul 2005 4:08 PM
Amil
Hi all,

Does it matter that when i view the GUID data using the Query Analyzer, the
characters are all in uppercase. Whereas, in .Net, the guid is in lower case?

Author
28 Jul 2005 4:12 PM
Aaron Bertrand [SQL Server MVP]
Does it matter for what?  Could you be more specific?



Show quote
"Amil" <A***@discussions.microsoft.com> wrote in message
news:443D5B31-F33D-463D-B034-CD22A3084997@microsoft.com...
> Hi all,
>
> Does it matter that when i view the GUID data using the Query Analyzer,
> the
> characters are all in uppercase. Whereas, in .Net, the guid is in lower
> case?
Author
28 Jul 2005 4:39 PM
Amil
"Aaron Bertrand [SQL Server MVP]" wrote:

> Does it matter for what?  Could you be more specific?
>

Specifically, when passing a .Net guid to SQL Server stored proc, does it
affect the equality of the two values.
Example:
stored proc: sp_test @rowguid
  - uses a WHERE clause: rowguid = @rowguid

Now, if the guid in .net has lowercased characters but in sqlserver
database, they are uppercased, will this affect the WHERE clause?
Author
28 Jul 2005 5:03 PM
Aaron Bertrand [SQL Server MVP]
> Specifically, when passing a .Net guid to SQL Server stored proc, does it
> affect the equality of the two values.
> Example:
> stored proc: sp_test @rowguid
>  - uses a WHERE clause: rowguid = @rowguid
>
> Now, if the guid in .net has lowercased characters but in sqlserver
> database, they are uppercased, will this affect the WHERE clause?

Did you try it?
Author
28 Jul 2005 5:27 PM
Amil
I just noticed that when viewing data - guids, in the VS IDE - server
explorer, they are displayed in lower case. Viewing the same data using the
Query Analyzer, they are in uppercase.  As to 'trying' it, I am still playing
around with my codes and still have problems building/compiling so I am not
there yet.

Show quote
"Aaron Bertrand [SQL Server MVP]" wrote:

> > Specifically, when passing a .Net guid to SQL Server stored proc, does it
> > affect the equality of the two values.
> > Example:
> > stored proc: sp_test @rowguid
> >  - uses a WHERE clause: rowguid = @rowguid
> >
> > Now, if the guid in .net has lowercased characters but in sqlserver
> > database, they are uppercased, will this affect the WHERE clause?
>
> Did you try it?
>
>
>
Author
28 Jul 2005 5:36 PM
Aaron Bertrand [SQL Server MVP]
> As to 'trying' it, I am still playing around with my codes
> and still have problems building/compiling so I am
> not there yet.

My point is that you could easily test your question yourself with a few
lines of code (no compilation, nor waiting for answers, required).  Here,
let me help you along, because I guess this is a pretty difficult scenario
to conjure up.

DECLARE @g1 UNIQUEIDENTIFIER,
    @g2 UNIQUEIDENTIFIER
SET @g1 = UPPER(NEWID())
SET @g2 = LOWER(@g1)
IF @g1 = @g2
PRINT 'Same'
ELSE
PRINT 'Not Same'
Author
28 Jul 2005 5:43 PM
David Gugick
Easy to test. No, it makes no difference. It also makes no difference if
you use a unicode string.

create table #guid_test (
myguid uniqueidentifier not null)

insert into #guid_test values (newid())

Select * from #guid_test

myguid
------------------------------------
D9F6BDF5-11C4-4C4C-8380-6F2ACD77966B

Select myguid
from #guid_test
where myguid = LOWER('D9F6BDF5-11C4-4C4C-8380-6F2ACD77966B')
UNION ALL
Select myguid
from #guid_test
where myguid = UPPER('D9F6BDF5-11C4-4C4C-8380-6F2ACD77966B')

myguid
------------------------------------
D9F6BDF5-11C4-4C4C-8380-6F2ACD77966B
D9F6BDF5-11C4-4C4C-8380-6F2ACD77966B

Drop Table #guid_test



--
David Gugick
Quest Software
www.imceda.com
www.quest.com
Author
28 Jul 2005 5:45 PM
Thomas Coleman
No, it will make no difference. SQL's parsing engine for guids is
case-insensitive.  Thus the following queries:

Select * From Table1 Where GuidCol = '4CCE2DA3-1D80-4A63-8E1B-FECA307275AC'
Select * From Table1 Where GuidCol = '4cce2da3-1d80-4a63-8e1b-feca307275ac'
Select * From Table1 Where GuidCol = '4cCe2Da3-1D80-4A63-8E1b-fEcA307275aC'

Will all return the same resultset.



Thomas



Obviously it will make absolutely no difference if the database is not set to
binary sorting. It is only in this one scenario that I could even conceive of
there being a difference. However, I believe that the encoding is always case
insensitive so it shouldn't make a difference.

Show quote
"Amil" <A***@discussions.microsoft.com> wrote in message
news:3285E758-4F85-4615-B376-BEEB92B646CB@microsoft.com...
>
>
> "Aaron Bertrand [SQL Server MVP]" wrote:
>
>> Does it matter for what?  Could you be more specific?
>>
>
> Specifically, when passing a .Net guid to SQL Server stored proc, does it
> affect the equality of the two values.
> Example:
> stored proc: sp_test @rowguid
>  - uses a WHERE clause: rowguid = @rowguid
>
> Now, if the guid in .net has lowercased characters but in sqlserver
> database, they are uppercased, will this affect the WHERE clause?
>
Author
28 Jul 2005 4:16 PM
Anith Sen
Not really, you can use LOWER() or UPPER() functions if needed to change the
case.

--
Anith
Author
28 Jul 2005 6:29 PM
Michael C#
UniqueIdentifiers are stored as a 16-byte binary value in SQL Server.  What
you are seeing when you PRINT it is a formatted hexadecimal representation
of those 16 binary bytes.  The only way the case should affect your results
is if you are CASTing it to a CHAR or VARCHAR *and* your database is using a
Case Sensitive Collation.

Show quote
"Amil" <A***@discussions.microsoft.com> wrote in message
news:443D5B31-F33D-463D-B034-CD22A3084997@microsoft.com...
> Hi all,
>
> Does it matter that when i view the GUID data using the Query Analyzer,
> the
> characters are all in uppercase. Whereas, in .Net, the guid is in lower
> case?

AddThis Social Bookmark Button