MySQL
database design
NULL values
empty strings
data management

MySQL, better to insert NULL or empty string?

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

NULL and '' do not mean the same thing in MySQL. NULL means "unknown, missing, or not applicable," while the empty string means "known value, and that value is an empty string." The better choice depends on your data semantics, not on a blanket performance rule.

If your application treats those meanings differently, your schema should too. Using the wrong one makes queries, constraints, and business logic much harder to reason about later.

What NULL Means

NULL is not a string. It represents the absence of a value.

That changes query behavior:

sql
SELECT *
FROM users
WHERE middle_name IS NULL;

You cannot reliably test NULL with ordinary equality operators:

sql
-- wrong
WHERE middle_name = NULL

Instead, use IS NULL and IS NOT NULL.

What the Empty String Means

The empty string is a real string value of length zero:

sql
SELECT *
FROM users
WHERE middle_name = '';

This says the column was given a value and that value is intentionally empty. That is very different from "we do not know the value" or "the field does not apply."

Choose Based on Semantics

Use NULL when:

  • the value is unknown,
  • the value has not been provided,
  • the field does not apply to this row.

Use '' when:

  • the empty string is a legitimate business value,
  • your application explicitly distinguishes empty text from missing text,
  • the user intentionally entered a blank value and that distinction matters.

For many optional text columns, NULL is the more truthful representation of missing data.

Query and Aggregate Differences

The distinction affects aggregates and predicates:

sql
SELECT COUNT(middle_name) FROM users;

This counts only non-NULL values. Empty strings are still counted, because they are real values.

Likewise:

sql
SELECT AVG(score) FROM tests;

ignores NULL scores, but there is no equivalent concept of an "empty numeric value" for a number column.

That is why choosing between NULL and '' changes not just storage, but also query meaning.

Application Logic Gets Cleaner When Semantics Are Clear

Suppose a middle_name column is optional. If a user simply did not provide one, NULL is usually clearer. If you instead store '', every query and every downstream service has to remember that empty string also means "missing."

That creates accidental complexity:

sql
WHERE middle_name IS NULL OR middle_name = ''

A cleaner schema often avoids needing both cases to mean the same thing.

That also helps application code. If one representation means "missing" and the other means "explicitly empty," your validation, API responses, and analytics can stay consistent instead of encoding the same absence in two different ways.

That consistency pays off for years.

Common Pitfalls

  • Using '' and NULL interchangeably even though the application means different things by them.
  • Writing = NULL instead of IS NULL.
  • Storing empty strings as a placeholder for "unknown" and then complicating every query later.
  • Assuming the decision is mostly about performance. It is primarily about data semantics.
  • Forgetting that aggregates treat NULL differently from ordinary values.

Summary

  • 'NULL means no value; '' means a real string value of length zero.'
  • Choose based on business meaning, not habit.
  • Use NULL for unknown, missing, or not-applicable data.
  • Use '' only when empty text is a legitimate stored value.
  • Clear semantics make queries, validation, and reporting much easier.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.