A NULL in a column means that the user or application has made no entry in that column. A data value for the column is unknown or not available.
NULL does not mean the same as zero (numerical values) or blank (character values). Rather, NULL values allow you to distinguish between a deliberate entry of zero for numeric columns or blank for character columns and a non-entry, which is NULL for both numeric and character columns.
NULL can be entered in a column where NULL values are permitted, as specified in the create table statement, in two ways:
Default If no data is entered, and the column has no other default setting, NULL is entered.
Explicit entry You can explicitly enter the value NULL by entering the word NULL (without quotation marks).
If the word NULL is typed in a character column with quotation marks, it is treated as data, not as a null value.
For example, the DepartmentHeadID column of the Departments table allows nulls. You can enter two rows for departments with no manager as follows:
INSERT INTO Departments (DepartmentID, DepartmentName) VALUES (201, 'Eastern Sales') INSERT INTO Departments VALUES (202, 'Western Sales', null);
When NULLS are retrieved, displays of query results in Interactive SQL show (null) in the appropriate position:
SELECT * FROM Departments;
DepartmentID | DepartmentName | DepartmentHeadID |
---|---|---|
100 | R & D | 501 |
200 | Sales | 904 |
300 | Finance | 1293 |
400 | Marketing | 1576 |
500 | Shipping | 703 |
201 | Eastern Sales | (null) |
202 | Western Sales | (null) |