SQL NULL Values

NULL Values

SQL NULL value represent a field or column where no value is mentioned. NULL value is not equal to zero or blank space. By default a column may contain NULL values. Here we will see how we can work with NULL values.

Below is a Student table containing NULL values in LastName field for RollNumber 1002 and 1005.

NULL

So if you will insert values and you are not mentioning any value for a column then it will save that column with NULL value. To filter NULL rows from a table you have to use specific operators as IS NULL or IS NOT NULL, you cannot use <,> or = operator to filter NULL values.

Here we will see couple of examples for the same.

SELECT *FROM Student WHERE LastName IS NULL

ISNULL

So, after filtering with IS NULL operator it has returned two rows where LastName column has NULL values.

Now we will use IS NOT NULL operator on the same table to find the records where LastName column is not containing any NULL values.

SELECT *FROM Student WHERE LastName IS NOT NULL

ISNOTNULL

Now you can observe in LastName column there is no value containing NULL values.

Reference: Manzoor Siddiqui [www.SQLServerLog.com]

CLICK HERE to watch live practical.

You may also like...

Leave a Reply

Your email address will not be published.