Database 2024-03-30

NULL in Database Design: Common Pitfalls and Best Practices

Learn how NULL works in relational databases, the three-valued logic problem, common query mistakes with NULL, and schema design strategies to avoid NULL-related bugs.

Read in: ja
NULL in Database Design: Common Pitfalls and Best Practices

What is NULL

Indicates "value does not exist" or "value is unknown."

Cannot be compared like a value because it is not a value.

It is not an empty set (a set with 0 elements) but is considered a non-existent set.

NULL Contrary to Relational Model

The relational model is based on the closed world assumption (assuming that anything not proven true is false), and NULL contradicts this.

The relational model is based on binary logic, so three-valued logic, which includes something other than true and false, is unacceptable.

Impact of NULL

Measures Against NULL

Empty String vs. NULL

An empty string has a length of 0 and is an existing string, whereas NULL is a non-existent set, and the two are distinguished.

Cases Allowing NULL

It may be acceptable to allow NULL when dealing with data that does not fit the relational model.

References

Tags: DB
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
☕ Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles