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
๐ŸŒ
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)....
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ sql queries โ€บ find null or empty values in sql
Find Null or Empty Values in SQL Baeldung on SQL
August 20, 2025 - The TRIM function removes any leading or trailing spaces in the column value so that a string containing only blank spaces is treated as empty. Finally, the query filters rows where the trimmed code value is an empty string. Combining the COALESCE function with TRIM allows us to retrieve rows containing empty or NULL values effectively. Apart from the ANSI SQL standards, some database management systems and dialects of SQL provide database-specific functions and operators to handle NULL values.
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.

๐ŸŒ
Reddit
reddit.com โ€บ r/sqlserver โ€บ counting rows where all columns are either null or empty in the row?
r/SQLServer on Reddit: Counting rows where ALL columns are either null or empty in the row?
September 26, 2024 -

I'd rather not write a bunch of AND clauses, so is there a quick, efficient way to do this?

I'm importing some data with 10 fields into a SQL Server from a CSV file. Occasionally this file has null/empty values across all the cells/columns.

What I'd like to do is just write one relatively short sql statement to simply count (at first) all these rows. I'd rather do it without doing something like:

...and (column1 is null or column1 = '')
...and (column2 is null or column2 = '')

etc...

Is there a good way to do this, or am I stuck with the above?

๐ŸŒ
DevArt
blog.devart.com โ€บ home โ€บ how to โ€บ how to handle null or empty values in sql server
How to Handle Null or Empty Values in SQL Server
December 19, 2024 - SELECT Color ,Size ,ProductLine ,Class ,Style FROM dbo.[Product.Test] WHERE (Color IS NULL OR TRIM(Color) = '') OR (Size IS NULL OR TRIM(Size) = '') OR (ProductLine IS NULL OR TRIM(ProductLine) = '') OR (Class IS NULL OR TRIM(Class) = '') OR (Style IS NULL OR TRIM(Style) = '') It helps us ensure there are no empty or meaningless values in the specified column. In addition to SQL queries, Microsoft SQL Server offers built-in functions specifically designed to handle NULL values.
๐ŸŒ
W3Schools
w3schools.com โ€บ mysql โ€บ mysql_null_values.asp
MySQL NULL Values - IS NULL and IS NOT NULL
SELECT column_names FROM table_name ... the "Customers" table in the Northwind sample database: The IS NULL operator is used to test for empty values (NULL values)....
Find elsewhere
๐ŸŒ
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 - In a Table Column sometimes there can be no actual or valid data and it could be NULL or Empty ('') or some space value saved. There are many methods or functions to identify the NULL or Empty values. Below are some of them: ... Explained below with examples, the above five methods. Below is the Table 'StudentsInfo' with data used for the examples in this article: ... This key word returns any records with NULL value in the column specified in a Table.
๐ŸŒ
Coginiti
coginiti.co โ€บ home โ€บ beginner โ€บ sql is null
What is the IS NULL Operator in SQL? - Coginiti
September 25, 2023 - This information can be used to fill in missing data or to identify areas where data is lacking and needs to be collected. 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.
๐ŸŒ
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.
๐ŸŒ
DotFactory
dofactory.com โ€บ sql โ€บ where-isnull
SQL IS NULL | IS NOT NULL
SELECT C.Id, FirstName, LastName, TotalAmount FROM Customer C LEFT JOIN [Order] O ON C.Id = O.CustomerId WHERE TotalAmount IS NULL Try it live ... IS NULL syntax. SELECT column-names FROM table-name WHERE column-name IS NULL
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ sql โ€บ sql-is-null-operator
SQL IS NULL Operator - GeeksforGeeks
December 31, 2023 - We can use the IS NULL operator with multiple columns. For instance, to filter rows where either email or coding_score is NULL, use the OR operator: ... The COUNT() function can be used to count the number of NULL values in a column.
๐ŸŒ
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

๐ŸŒ
SQLServerCentral
sqlservercentral.com โ€บ forums โ€บ topic โ€บ check-the-variable-is-empty-or-null โ€บ page โ€บ 3
Check the Variable is Empty or Null โ€“ SQLServerCentral Forums
September 9, 2014 - Perhaps internally SQL Server treats ISNULL() like any other scalar function, so it prevents the optimiser from being really efficient and has to do more stuff separately for each row. Sure, but I still prefer a single check. Note that the code should include the comments to keep clarity on what it is doing. WHERE MyNullableCol != '' --This will avoid NULLs and empty strings