IS NULL condition 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

  1. If the expression has NULL value, the condition returns TRUE result
  2. 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

4 ★ | 1 Vote

May be interested

  • EXISTS condition in SQL ServerEXISTS condition in SQL Server
    in sql server (transact-sql) condition exists is correct to associate with the internal query (subquery).
  • How to Check Null in CHow to Check Null in C
    in c, null is a symbolic constant that always points to a nonexistent point in the memory. although many programmers treat it as equal to 0, this is a simplification that can trip you up later on. it's best to check your pointers against...
  • Conditions NOT in SQL ServerConditions NOT in SQL Server
    the not condition in sql server (transact-server) is also called the not operator, which is used to negate conditions in select, insert, update, and delete statements.
  • HAVING clause in SQL ServerHAVING clause in SQL Server
    the having clause is used in conjunction with the group by clause in sql server (transact-sql) to limit the group of returned rows, only when the condition is met is true.
  • Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 10Microsoft Windows PowerShell and SQL Server 2005 SMO - Part 10
    in part 10, i will show you how to use powershell scripts in conjunction with smo and parameters to create sql server scripts. creating sql server scripts is an important task for administrators and sql server database development professionals.
  • OR conditions in SQL ServerOR conditions in SQL Server
    the or condition in sql server (transact-sql) is used to check multiple conditions.
  • WHILE loop in SQL ServerWHILE loop in SQL Server
    the while loop is used if you want to run a code repeatedly when the given condition returns true. let's find out how to use while in sql server with network administrator.
  • AND conditions in SQL ServerAND conditions in SQL Server
    in sql server, the and condition (or and operator) is used to test two or more conditions.
  • ISNULL function in SQL ServerISNULL function in SQL Server
    in sql server, the isnull function allows you to return an alternate value when an input expression is null.
  • IN conditions in SQL ServerIN conditions in SQL Server
    the in condition is used in sql server (transact-sql) to minimize the need to use too many or conditions.