The unique identifier datatype is used to uniquely identify a row across various databases in the network. The value has 36 characters inclusive of digits from 0 to 9,alphabets from A to F and hypen. Suppose you have a string of 36 characters and want to know if it is really an uniqueidentifier. You can use either of these methods
Method 1
declare @uid char(36) set @uid='6F9619FF-8B80-D011-B42D-00C04FC964FF' select case when @uid like '[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F]-[0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F][0-9A-F]' then 'yes' else 'no' end
Method 2
declare @uid char(36) set @uid='6F9619FF-8B80-D011-B42D-00C04FC964FF' select case when @uid like replicate('[0-9A-F]',8)+'-'+ replicate('[0-9A-F]',4)+'-'+ replicate('[0-9A-F]',4)+'-'+ replicate('[0-9A-F]',4)+'-'+ replicate('[0-9A-F]',12) then 'yes' else 'no' end
Tags: t-sql, sql_server, sqlserver, tsql, BRH, uid, uniqueidentifier,
Thanks for sharing