IS NULL condition in SQL Server
The IS NULL condition is used to check NULL values in SQL Server.
In SQL Server (Transact-SQL), the condition IS NULL is used to check the NULL value. A NULL value in a table is a value in an empty field, in other words, a field with no value.
Syntax condition IS NULL
IS NULL 'expression'
Variable name or variable value
expression
Values to check if the value is NULL.
Note
- If the expression has NULL value, the condition returns TRUE result
- If the expression has no NULL value, the condition returns FALSE
For example - SELECT command
Let's look at the example condition NULL in the SELECT statement below.
SELECT *
FROM nhanvien
WHERE ho IS NULL;
This example will return all records in the table if the employee's last name is left blank - or called NULL.
Example - INSERT command
INSERT INTO nhanvien
((nhanvien_id, ho, ten)
SELECT nhanvien_id, ho, ten
FROM danhba
WHERE ten IS NULL;
This command will fill in records from the list into the user table in the fields whose employee name is left blank.
Example - UPDATE command
UPDATE nhanvien
SET ten = 'Unknown'
WHERE ten IS NULL;
In this example, the records in the user table whose blank name value will be updated.
Example - DELETE command
DELETE FROM nhanvien
WHERE ho IS NULL;
This command will delete all records in the table if the value in the last name field is NULL.
Previous article: IN conditions in SQL Server
Next lesson: IS NOT NULL condition in SQL Server
You've just finished reading the article "IS NULL condition in SQL Server" edited by the TipsMake team. You can save is-null-condition-in-sql-server.pdf to your computer here to read later or print it out. We hope this article has provided you with many useful tech tips and tricks. You can search for similar articles on tips and guides. Thank you for reading and for following us regularly.