|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Uniqueidentifier GUID questionHi 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? 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? "Aaron Bertrand [SQL Server MVP]" wrote: Specifically, when passing a .Net guid to SQL Server stored proc, does it > Does it matter for what? Could you be more specific? > 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? > Specifically, when passing a .Net guid to SQL Server stored proc, does it Did you try 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? 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? > > > > As to 'trying' it, I am still playing around with my codes My point is that you could easily test your question yourself with a few > and still have problems building/compiling so I am > not there yet. 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' 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 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? > Not really, you can use LOWER() or UPPER() functions if needed to change the
case. -- Anith 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? |
|||||||||||||||||||||||