SQL Server IS NULL Condition (Operator)

The SQL Server IS NULL operator is used to test for a NULL value.

Syntax:

expression IS NULL  

Parameter explanation

expression: It specifies a value whether it is NULL.

Note:
If the expression is NULL value then the condition evaluates to TRUE.
If expression is not a NULL value, the condition evaluates to FALSE.

IS NULL Operator with SELECT Statement

Example:

SELECT *  

FROM [javatpoint].[dbo].[Employees]  

WHERE salary IS NULL;

Output:

SQL Is null condition 1

IS NULL Operator with INSERT Statement

Example:

INSERT INTO [javatpoint].[dbo].[Employees]  

(id, name, salary)  

SELECT id, name, Department  

FROM [javatpoint].[dbo].[Employee2]  

WHERE name IS NULL;

Output:

SQL Is null condition 2

Note: This displays “0 rows affected” because there is no NULL value in name in the “Employees” table.

IS NULL Operator with UPDATE Statement

Example:

Update the salary of the employees in “Employees” table and set to 100000 where salary is NULL.

UPDATE Employees  

SET salary = '100000'  

WHERE salary IS NULL;

Output:

SQL Is null condition 3

You can verify it by using SELECT query:

SQL Is null condition 4

IS NULL Operator with DELETE Statement

Delete the employees from the “Employees” table where age is NULL.

Example:

DELETE FROM [javatpoint].[dbo].[Employees]  

WHERE age IS NULL;

Output:

SQL Is null condition 5

You can verify it by using SELECT query:

SQL Is null condition 6

You can see that there is no NULL value in age in the above table.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *