Jump to content

Null (SQL)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Asterdroid (talk | contribs) at 18:45, 4 March 2007. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Attributes in tables in SQL database management systems can optionally be designated as NULL. This indicates that the actual value of the column is unknown or not applicable.

In SQL DBMSs, the result of comparing a value (either a constant or a value stored in a table) with NULL using comparison operators like = or => is neither TRUE nor FALSE but rather unknown. Furthermore, comparing two NULLs this way is also unknown because an unknown value might not be equal to any other value. To test if the values in a column are NULL or are not NULL, the following syntax must be used:

 column IS NULL
 
 column IS NOT NULL

Because of this, special care must be taken when joining tables on columns that can contain NULLs.

Strictly spoken, NULL is not a value since it is an inherent property of values that they can be compared with other values of the same data type.

Because NULL means "unknown value", negation of NULL results in NULL. In other words, since you do not know the value of a particular expression then you do not know the value of the negation of that same expression.

NULL is untyped in SQL. Therefore, it is sometimes mandatory to explicitly cast NULLs so that the database system is of the intended data type. For example, if overloaded functions are supported, the DBMS cannot resolve to the correct function without knowing the data types of all paramaters.

See also