NULL is a replacement value that means nothing is in a particular cell. However, it does NOT represent zero and will not come up true in a comparison with zero. NULL is the default value within a cell where nothing has been entered. When a table is CREATed or ALTERed it may be designated as NOT NULL using the following syntax:

CREATE TABLE table ( column1 int NOT NULL, column2 varchar(255) NOT NULL, column3 varchar(255) )

Note in this case that column1 and column2 have been given the NOT NULL constraint. This means that a query that leaves these cells blank would throw an error. There are two operators that can be used to determine the status of the data within cells, IS NULL, and IS NOT NULL.

IS NULL is used because there is no other operator that will compare the data in the cell with the NULL condition. (=, >, <> will not work.) The comparison is performed in the WHERE clause.

SELECT column FROM table WHERE column IS NULL

IS NOT NULL may also be used with the expected result.


Interesting Pages