NULL and UNKNOWN (Transact-SQL)

**APPLIES TO:** ![yes](media/yes.png)SQL Server (starting with 2008) ![yes](media/yes.png)Azure SQL Database ![no](media/no.png)Azure SQL Data Warehouse ![yes](media/yes.png)Parallel Data Warehouse

NULL indicates that the value is unknown. A null value is different from an empty or zero value. No two null values are equal. Comparisons between two null values, or between a null value and any other value, return unknown because the value of each NULL is unknown.

Null values generally indicate data that is unknown, not applicable, or to be added later. For example, a customer’s middle initial may not be known at the time the customer places an order.

Note the following about null values:

When null values are present in data, logical and comparison operators can potentially return a third result of UNKNOWN instead of just TRUE or FALSE. This need for three-valued logic is a source of many application errors. Logical operators in a boolean expression that includes UNKNOWNs will return UNKNOWN unless the result of the operator does not depend on the UNKNOWN expression. These tables provide examples of this behavior.

The following table shows the results of applying an AND operator to two Boolean expressions where one expression returns UNKNOWN.

Expression 1 Expression 2 Result
TRUE UNKNOWN UNKNOWN
UNKNOWN UNKNOWN UNKNOWN
FALSE UNKNOWN FALSE

The following table shows the results of applying an OR operator to two Boolean expressions where one expression returns UNKNOWN.

Expression 1 Expression 2 Result
TRUE UNKNOWN TRUE
UNKNOWN UNKNOWN UNKNOWN
FALSE UNKNOWN UNKNOWN

See Also

AND (Transact-SQL)
OR (Transact-SQL)
NOT (Transact-SQL)
IS NULL (Transact-SQL)