MySQL
NULL

NULLs Are Not The Same – A Guide

Author: Lukas Vileikis
Length: 4 MINS
Type: Guide
Published: 2023-10-03
Intro
In this blog, we’re walking you through the upsides and downsides in NULLs in MySQL – have a read!
Tools used in the tutorial
Tool
Description
DbVisualizer
Top rated database management tool and sql client
MySQL 8.0+
The MySQL database version 8 or later

Everyone has heard about NULL values – one can hardly find a DBA or any developer that didn’t make use or seen such values in his work. Part of that is because NULL values signify the absence of something – but another part of it may be attributed to the fact that we only see the tip of the iceberg when it comes to them. In this blog, we will tell you everything you need to know about NULL values in MySQL and beyond.

What Are NULL Values?

NULL values are just what you think they are – a string signifying nothing existing in a column. NULL values are frequently implemented into any table in a very simple and straightforward manner – a query like so will do:

1
CREATE TABLE demo_table (
2
`column_1` VARCHAR(25) [NOT] NULL [DEFAULT…]
3
);
NULL Values when Creating a Table.

↑  NULL Values when Creating a Table.

Such a query can be modified to let a table know that whenever any data is inserted into that column, it should or shouldn’t be NULL with a default value of X (the default value can also be NULL which is beneficial in some cases.)

You get it – NULL values exist to signify a user that no value exists in a column. As easy as that. Don’t confuse it with the column being empty though – empty values and NULL values are not the same as you will soon find out.

How to Work with NULL Values?

Fortunately or not, all developers and DBAs will encounter NULL values during some course of their work – and for that, they must know how to properly work with those values. It is wise to follow a couple of key rules:

  • NULL means false.
  • NULL values can be specified as the default value of a column and there’s nothing wrong with that – such a practice would even help DBAs to search for values in a column later on.
  • NULL values can be searched for with the IS NULL or IS NOT NULL operators.
  • NULL means “a missing value which is unknown to the DBMS”, not “nothing.”
  • Comparison operators like =, <=, >= or similar cannot be used to search for NULL values.
  • Partitions treat NULL values differently than other values.

Keeping these things in mind, we can move further. The first thing you need to know is that you cannot compare NULL values since all and any comparisons with NULL will equal to NULL. Thus, getting a valid result is simply impossible.

Second very important thing to note that users who search for NULL should search for such values without comparison or equality operators and instead, use IS NULL or IS NOT NULL operators.

NULL values can however be very beneficial for those who work with analytical or other data because employing them together with default values (e.g. specifying the default value of a column to be NULL instead of some other value) can help users save time and know what to expect once data is inserted into their database – if no data would be inserted, the results of the column would be NULL and queries like LOAD DATA INFILE would be significantly faster on columns having the NULL value if we compare those kinds of queries with queries like UPDATE that we would need to run after inserting the data itself.

Those who work with partitions and need NULL values should be vary of the fact that MySQL does not prevent users from using NULL as part of a partitioning expression, yet all of the values containing NULL will always be inserted into the lowest partition possible. We won’t get into the nitty-gritty detail around this, but those who are interested in the specifics should have a read through How MySQL Partitioning Handles NULL over in the documentation.

NULL does not equal “nothing” and contrary to a popular belief, NULL queries will occupy data on the disk, so if you’re concerned about that, please set the default value of your columns to be empty (“”) or NOT NULL.

Other Things to Know

Aforementioned things are pretty much everything you need to know about NULL values in a couple of paragraphs – however, there are other things you should do to empower your database instances, no matter which kind of DBMS you find yourself running.

One of those things is the usage of SQL clients like DbVisualizer – as a SQL client, DbVisualizer is used by notable companies such as NASA, Google, Tesla, Saab and others, and it can help you work with any database management system you desire. With its powerful features each crafted to be able to solve the most pressing real-world database problems faced by developers and DBAs alike, DbVisualizer is a great choice for CEOs, team leaders, or engineers alike.

Have a look through the features provided by the tool, then grab an evaluation trial – you will not be disappointed.

Summary

NULL values in various database management systems and especially MySQL are treated differently – partitions insert them into the lowest partition possible, equality operations are not possible, and nothing isn’t the same as NULL either – with that said, NULL values can be very beneficial in some cases: wield their sword powerfully enough, and you will surely benefit from all of the upsides they provide to DBAs and developers alike.

We hope that this blog has been informational and that you will explore our blog for more information in the future, and until next time!

DbVisualizer SQL Client.
About the author
Lukas Vileikis.
Lukas Vileikis
Lukas Vileikis is an ethical hacker and a frequent conference speaker. He runs one of the biggest & fastest data breach search engines in the world - BreachDirectory.com, frequently speaks at conferences and blogs in multiple places including his blog over at lukasvileikis.com.
SIGN UP TO RECEIVE THE TABLE'S ROUNDUP
More from the table
TITLE
AUTHOR
Gayatri Sachdeva
TAGS
DBA'S
DronaHQ
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
TITLE
AUTHOR
Bonnie
TAGS
Generation
TITLE
AUTHOR
Bonnie
TAGS
Joins
TITLE
AUTHOR
Igor Bobriakov
TAGS
MySQL
Security
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Operators
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
NULL
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Reserved words
TITLE
AUTHOR
Igor Bobriakov
TAGS
Oracle
TITLE
AUTHOR
Antonello Zanini
TAGS
DELETE
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
MySQL
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
JSON
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
Null
TITLE
AUTHOR
Antonello Zanini
TAGS
Driver
JDBC
ODBC
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
Connection
TITLE
AUTHOR
Lukas Vileikis
TAGS
Deduplication
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
SQL
Functions
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Math
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Docker
MySQL
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Views
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Index
TITLE
AUTHOR
Bonnie
TAGS
BigQuery
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
Join
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
PostgreSQL
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
PrestoDb
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Ansible
Automation
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
PostgreSQL
NoSQL
JSON
TITLE
AUTHOR
Igor Bobriakov
TAGS
Oracle
Data types
TITLE
AUTHOR
TheTable
TAGS
ElasticSearch
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Security
TITLE
AUTHOR
Lukas Vileikis
TAGS
Language
Design
TITLE
AUTHOR
Lukas Vileikis
TAGS
CRUD
DELETE
TITLE
AUTHOR
Lukas Vileikis
TAGS
CRUD
UPDATE
TITLE
AUTHOR
Lukas Vileikis
TAGS
CRUD
SELECT
TITLE
AUTHOR
Lukas Vileikis
TAGS
CRUD
INSERT
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
PostgreSQL
TITLE
AUTHOR
TheTable
TAGS
Bug
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Daemon
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Partitions
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
Migration
MySQL
PostgreSQL
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
hstore
TITLE
AUTHOR
TheTable
TAGS
SQL
TITLE
AUTHOR
Igor Bobriakov
TAGS
SQL server
Security
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Visualize
TITLE
AUTHOR
TheTable
TAGS
MySQL
TITLE
AUTHOR
Lukas Vileikis
TAGS
SQL
Security
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
TheTable
TAGS
PostgreSQL
Docker
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Connection
TITLE
AUTHOR
Lukas Vileikis
TAGS
Performance
TITLE
AUTHOR
Lukas Vileikis
TAGS
Security
TITLE
AUTHOR
Antonello Zanini
TAGS
Columns
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Performance
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
SQL
TITLE
AUTHOR
Lukas Vileikis
TAGS
Performance
Indexes
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Subquery
TITLE
AUTHOR
Lukas Vileikis
TAGS
Performance
TITLE
AUTHOR
Lukas Vileikis
TAGS
ACID
TITLE
AUTHOR
Lukas Vileikis
TAGS
ALTER TABLE
TITLE
AUTHOR
TheTable
TAGS
MySQL
Ports
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Security
TITLE
AUTHOR
Lukas Vileikis
TAGS
ACID
MySQL
Security
TITLE
AUTHOR
Antonello Zanini
TAGS
BLOB
TITLE
AUTHOR
TheTable
TAGS
Foreign Key
PostgreSQL
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
PostgreSQL
Concurrency
TITLE
AUTHOR
Lukas Vileikis
TAGS
Security
Encryption
TITLE
AUTHOR
Lukas Vileikis
TAGS
Security
TITLE
AUTHOR
Bonnie
TAGS
Security
PostgreSQL
TITLE
AUTHOR
Antonello Zanini
TAGS
Subquery
TITLE
AUTHOR
Antonello Zanini
TAGS
Transactions
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Data structures
TITLE
AUTHOR
Antonello Zanini
TAGS
MySQL
TITLE
AUTHOR
Lukas Vileikis
TAGS
SSH
TITLE
AUTHOR
Antonello Zanini
TAGS
Stored procedure
MySQL
TITLE
AUTHOR
Antonello Zanini
TAGS
Triggers
TITLE
AUTHOR
Igor Bobriakov
TAGS
Microsoft SQL Server
Optimization
TITLE
AUTHOR
Bonnie
TAGS
PostreSQL
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Reusable queries
TITLE
AUTHOR
Antonello Zanini
TAGS
BIG Data
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Security
TITLE
AUTHOR
TheTable
TAGS
Beginner
SQL
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
CRUD
SQL Transactions
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Security
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
JSON
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
InnoDB
ibdata1
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
TITLE
AUTHOR
Scott A. Adams
TAGS
Filter
TITLE
AUTHOR
Scott A. Adams
TAGS
SQLite
TITLE
AUTHOR
Scott A. Adams
TAGS
Excel
Export
TITLE
AUTHOR
Scott A. Adams
TAGS
ERD
Join

The content provided on dbvis.com/thetable, including but not limited to code and examples, is intended for educational and informational purposes only. We do not make any warranties or representations of any kind. Read more here.