Supposing I’ve got a bit of SQL that filters data by a column which is of type UniqueIdentifier.
Select * from core.Pages WHERE PageId = '1DC4E71C-4E68-489D-A837-2C9BA8DCC1DC'
(This guid was generated by the NewID() function)
For the purposes of a quick test/sanity check I thought I’d replace one of the characters with an ‘x’ and run the query again. Imagine my surprise when I got an error message:
Conversion failed when converting from a character string to
uniqueidentifier.
I thought GUID or UniqueIdentifier was unlimited in its scope ie. any alphanumeric character could be replaced with any other but it seems that SQL Server has its own ideas about what constitutes a GUID. Any use of the letter ‘X’ generates this error. Other characters don’t seem to upset the RDBMS.
Can anyone explain this?
GUIDs are a hexidecimal number – it’s not just “any character can be used to replace any other character”, the resulting string must be a valid hexidecimal number. It’s not the GUID itself that is necessarily unique, it’s that the range of numbers that the GUID can represent (2^128) that the odds of the same GUID being generated twice within a system are negligible.