How to Check Whether a GUID is Empty GUID or Not?
As we understood in the previous section a GUID can be null which means that there is no value present in the row of the GUID column but when we are talking about whether GUID is empty or not then we have to think if a GUID has been in the form of multiple zeros which can be used to represent a 32 bit hexadecimal format if multiple zeros are present in the form of 32 bit hexadecimal format then we can say that a GUID is an empty GUID.
In order to check whether a GUID is an empty GUID instead of a null or value-based GUID, we can simply pass the GUID’s variable name inside the if statement and match it against the empty GUID’s hex code and return the result. As you can see in the code below:
Query:
Declare @guidtest UniqueIdentifier
Set @guidtest = '00000000-0000-0000-0000-000000000000'
If(@guidtest = '00000000-0000-0000-0000-000000000000')
Begin
Print ‘The GUID is Empty…’
End
Else
Begin
Print 'The GUID is not Empty… '
End
Output:
How to Check GUID is Null or Empty in SQL Server
GUID stands for Globally Unique Identifier, the GUID is a 16-byte long binary data type. the GUID is special because it is globally unique across all the databases, tables, and servers available. In the GUID there is a unique reference number present which is generated by the algorithm every time we execute the query to generate GUID. the GUID is stored as a 128-bit value but when it is displayed by the machine or system it is displayed as 32 hexadecimal digits. in this article we will learn what is GUID, why they are used as well as how to create them, and whether a GUID is null or empty in the SQL Server.