In a relational database, a null value is used when a column’s value is absent or ambiguous. A null is not a zero value or an empty string. In other words, It is a special marker used in SQL to denote the absence of a data value from the database.
As a value, a restriction, and a filter condition, NULL is utilized. NOT NULL, on the other hand, cannot be used as a value but will be used as a constraint and helps to filter the search results. The examples that will teach you how to utilize NOT NULL are provided below.
NOT NULL as a constraint:
CREATE TABLE tbEmployee (
iEmployeeID INT PRIMARY KEY,
vcEmployeeName VARCHAR(100) NULL,
dtHireDate DATETIME NOT NULL);
NOT NULL as a filter condition:
SELECT * FROM tblEmployee WHERE vcEmployeeName IS NOT NULL;
SELECT * FROM tblLocation WHERE (longitude IS NOT NULL AND latitude IS NOT NULL);
Hope you find this article helpful.
One comment