Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is an overuse of nullable columns in a database a "code smell"?

Tags:

I'm just stepping into a project and it has a fairly large database backend. I've started digging through this database and 95% of the fields are nullable.

Is this normal practice in the database world? I'm just a lowly programmer, not a DBA but I would think you would want to keep nullable fields to a minimum, only where they make sense.

Is it a "code smell" if most columns are nullable?

like image 576
AlexanderTheGreat Avatar asked Jun 23 '09 20:06

AlexanderTheGreat


People also ask

Are nulls OK in a database?

like most features of anything, nulls are fine only if you know how to use them. Remember that it does require another bit of storage for every row * every column that enable NULL.

What does nullable mean in database?

NULL meansnull value; it's not the same as zero or blank. NULL means that the users made no entry and often implies missing or otherwise undefined data. Because you can easily search for NULLs, people frequently use them to flag missing data. Nullability refers to the ability of a column to accept NULL values.

What does nullable column mean?

It's a boolean flag to tell if the columns is nullable (aka it can contains null). If nullable = 1 the column can contains null. Follow this answer to receive notifications.

What is the meaning of nullable in SQL?

A field with a NULL value is a field with no value. If a field in a table is optional, it is possible to insert a new record or update a record without adding a value to this field. Then, the field will be saved with a NULL value. Note: A NULL value is different from a zero value or a field that contains spaces.


1 Answers

Default values are typically the exception and NULLs are the norm, in my experience.

True, nulls are annoying.

It's also extremely useful because null is the best indicator of "NO VALUE". A concrete default value is very misleading, and you can lose information or introduce confusion down the road.

like image 81
hythlodayr Avatar answered Oct 13 '22 01:10

hythlodayr