Let's say that the record comes from a form to gather name and address information. Line 2 of the address will typically be blank if the user doesn't live in apartment. An empty string in this case is perfectly valid. I tend to prefer to use NULL to mean that the value is unknown or not given.

I don't believe the physical storage difference is worth worrying about in practice. As database administrators, we have much bigger fish to fry!

Answer from Larry Coleman on Stack Exchange
๐ŸŒ
Quora
quora.com โ€บ How-can-you-find-all-values-that-are-not-null-using-a-single-query-in-SQL-Server
How to find all values that are not null using a single query in SQL Server - Quora
Answer (1 of 4): We can use the below for single SELECT * FROM user WHERE username IS NOT NULL; We can use the below for multiple SELECT * FROM user WHERE username IS NOT NULL OR email IS NOT NULL OR description IS NOT NULL;
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ sql server โ€บ how-to-check-a-column-is-empty-or-null-in-sql-server
How to Check a Column is Empty or Null in SQL Server - GeeksforGeeks
January 31, 2024 - Select * from StudentsInfo WHERE Remarks IS NOT NULL ... The function ISNULL() returns all records with 'NULL' values and records having Empty value ('') or Spaces (' ') in the specified column.
Discussions

feature comparison - When to use NULL and when to use an empty string? - Database Administrators Stack Exchange
On the other side, when concatenating strings in Oracle. NULL varchars are treated as empty strings. ... When you want to express explicitly, that a value is assigned, you have to use something like ' '. And you have to worry whether trimming not empty results in NULL ยท select case when ltrim(' ') is null then 'null' else 'not null' end from dual ... Now looking at DBMS where '' is not identical to NULL (e.g. SQL... More on dba.stackexchange.com
๐ŸŒ dba.stackexchange.com
How to check for Is not Null And Is not Empty string in SQL server? - Stack Overflow
How can we check in a SQL Server WHERE condition whether the column is not null and not the empty string ('')? More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to handle a value which is not null but also not an empty string?
Cast it to binary to see what code points are actually there. More on reddit.com
๐ŸŒ r/SQL
12
5
March 12, 2024
"NOT NULL" property in SQL Server Express 2019
The case is that within SQL 2019 I set the "Not null" property in certain fields of some tables. The problem is that either from my development environment (Visual Studio) or from a stored procedure or from the table's record editor, it allows me to save a record even though I passed an empty ... More on learn.microsoft.com
๐ŸŒ learn.microsoft.com
3
0
May 8, 2021
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_null_values.asp
SQL NULL Values - IS NULL and IS NOT NULL
SELECT column_names FROM table_name ... a selection from the Customers table used in the examples: The IS NULL operator is used to test for empty values (NULL values)....
๐ŸŒ
SQLBolt
sqlbolt.com โ€บ lesson โ€บ select_queries_with_nulls
SQLBolt - Learn SQL - SQL Lesson 8: A short note on NULLs
Select query with constraints on NULL values SELECT column, another_column, โ€ฆ FROM mytable WHERE column IS/IS NOT NULL AND/OR another_condition AND/OR โ€ฆ; This exercise will be a sort of review of the last few lessons. We're using the same Employees and Buildings table from the last lesson, but we've hired a few more people, who haven't yet been assigned a building. Sorry but the SQLBolt exercises require a more recent browser to run.
Top answer
1 of 11
92

Let's say that the record comes from a form to gather name and address information. Line 2 of the address will typically be blank if the user doesn't live in apartment. An empty string in this case is perfectly valid. I tend to prefer to use NULL to mean that the value is unknown or not given.

I don't believe the physical storage difference is worth worrying about in practice. As database administrators, we have much bigger fish to fry!

2 of 11
28

I do not know about MySQL and PostgreSQL, but let me treat this a bit generally.

There is one DBMS namely Oracle which doesn't allow to choose it's users between NULL and ''. This clearly demonstrates that it is not necessary to distinguish between both. There are some annoying consequences:

You set a varchar2 to an empty string like this:

Update mytable set varchar_col = '';

the following leads to the same result

Update mytable set varchar_col = NULL;

But to select the columns where the value is empty or NULL, you have to use

select * from mytable where varchar_col is NULL;

Using

select * from mytable where varchar_col = '';

is syntactically correct, but it never returns a row.

On the other side, when concatenating strings in Oracle. NULL varchars are treated as empty strings.

select NULL || 'abc' from DUAL;

yields abc. Other DBMS would return NULL in these cases.

When you want to express explicitly, that a value is assigned, you have to use something like ' '.

And you have to worry whether trimming not empty results in NULL

select case when ltrim(' ') is null then 'null' else 'not null' end from dual

It does.

Now looking at DBMS where '' is not identical to NULL (e.g. SQL-Server)

Working with '' is generally easier and in most case there is no practical need to distinguish between both. One of the exceptions I know, is when your column represents some setting and you have not empty defaults for them. When you can distinguish between '' and NULL you are able to express that your setting is empty and avoid that the default applies.

๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ sql โ€บ is-not-null
SQL IS NOT NULL Condition: Syntax, Usage, and Examples
Use SQL IS NOT NULL in a WHERE clause to filter out records that contain empty or missing values in a column.
Find elsewhere
๐ŸŒ
AlmaBetter
almabetter.com โ€บ bytes โ€บ tutorials โ€บ sql โ€บ not-null-in-sql
NOT NULL in SQL
June 22, 2023 - NOT Null constraints are often ... table is made or included later in an existing table. ... Not null is a constraint used in SQL that ensures a value is not empty....
๐ŸŒ
Reddit
reddit.com โ€บ r/sql โ€บ how to handle a value which is not null but also not an empty string?
r/SQL on Reddit: How to handle a value which is not null but also not an empty string?
March 12, 2024 -

I have a table which contains some values which are not null. I thought it might be an empty sting but it was not an empty string either.

I copied that particular field from the table and tried an update statement to convert it into null but it didn't worked either . Kindly suggest something

๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_isnull.asp
W3Schools.com
SQL HOME SQL Intro SQL Syntax SQL Select SQL Select Distinct SQL Where SQL Order By SQL And SQL Or SQL Not SQL Insert Into SQL Null Values SQL Update SQL Delete SQL Select Top SQL Aggregate Functions SQL Min and Max SQL Count SQL Sum SQL Avg SQL Like SQL Wildcards SQL In SQL Between SQL Aliases ...
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ answers โ€บ questions โ€บ 387709 โ€บ not-null-property-in-sql-server-express-2019
"NOT NULL" property in SQL Server Express 2019 - Microsoft Q&A
May 8, 2021 - For instance, take a column MiddleName in Persons table. If MiddleName is the empty string, we know that this person does not have a middle name. If the value is NULL, we don't know the middle name of this person might be, or if the person has a middle name at all.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ sql โ€บ t-sql โ€บ queries โ€บ is-null-transact-sql
IS NULL (Transact-SQL) - SQL Server | Microsoft Learn
3 weeks ago - SELECT Name, Weight, Color FROM Production.Product WHERE Weight < 10.00 OR Color IS NULL ORDER BY Name; GO ยท The following example returns the full names of all employees with middle initials. SELECT FirstName, LastName, MiddleName FROM DIMEmployee WHERE MiddleName IS NOT NULL ORDER BY LastName DESC;
๐ŸŒ
Coginiti
coginiti.co โ€บ home โ€บ beginner โ€บ sql is null
What is the IS NULL Operator in SQL? - Coginiti
September 25, 2023 - In addition to the IS NULL operator, SQL also provides the IS NOT NULL operator, which is used to test for non-NULL values in a column. ... As a result, you would see the rows that are not empty or do not have NULL values.
๐ŸŒ
Hightouch
hightouch.com โ€บ sql-dictionary โ€บ sql-is-not-null
SQL IS NOT NULL - Syntax, Use Cases, and Examples | Hightouch
December 29, 2023 - You would use the SQL IS NOT NULL operator when you need to filter data from a table based on whether a column's value is not NULL. This is useful when you want to retrieve records with data present in a specific column or attribute, ensuring ...
๐ŸŒ
Oracle
docs.oracle.com โ€บ en โ€บ database โ€บ other-databases โ€บ nosql-database โ€บ 25.1 โ€บ sqlreferencefornosql โ€บ is-null-and-is-not-null-operators.html
IS NULL and IS NOT NULL Operators
April 28, 2025 - is_null_expression ::= ... is NULL. If the input expression returns more than one item, an error is raised. If the result of the input expression is empty, IS NULL returns false....
๐ŸŒ
SQLTeam
forums.sqlteam.com โ€บ sql server administration
How to see non null values? - SQL Server Administration - SQLTeam.com Forums
July 8, 2022 - I have a table which does not allow nulls in ColumnA. When I select * where ColumnA is not null, millions of rows are returned, most of them have no visible value . They may contain 1 or more spaces but how can I knowโ€ฆ
๐ŸŒ
W3Schools
w3schools.com โ€บ sql โ€บ sql_notnull.asp
SQL NOT NULL Constraint
The NOT NULL constraint enforces a column to NOT accept NULL values. This enforces a field to always contain a value, which means that you cannot insert a new record, or update a record without adding a value to this field.
๐ŸŒ
Programiz
programiz.com โ€บ sql โ€บ is-null-not-null
SQL IS NULL and IS NOT NULL (With Examples)
It has the following syntax: SELECT column1, column2, ... FROM table WHERE column_name IS NULL; ... Here, the above SQL query retrieves all the rows from the Employee table where the value of the email column is NULL. ... Note: Empty values are considered NULL.