A
A
Ayk722017-09-25 15:07:26
MySQL
Ayk72, 2017-09-25 15:07:26

Why is Null needed in MySQL?

Hello!
Perhaps this question may seem ridiculous or stupid, BUT.
I just can't figure out why MySQl needs NULL by default? In what cases should it be set?
As I understand it, it is put in cases where the field may be empty in some records. This is true?
Why not just leave it blank then? Why NULL? Does it provide any benefits?
And if it's a numeric field, then why not just set the default to 0, what's the difference?
Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey Budaev, 2017-09-25
@Markus_Kane

For a numeric field, the difference is that 0 may be the result of an arithmetic operation, while NULL indicates that the value was simply not provided.
Similarly - for an empty string and other data types.
NULL as a field property is read as NULLABLE - i.e. the value for this column is optional to be specified.

R
RidgeA, 2017-09-25
@RidgeA

"0", empty string, etc. it's the same value. NULL means no value.

A
Adamos, 2017-09-25
@Adamos

Well try setting "null value" for date or boolean field.
Suddenly, it will be 1970-01-01 and false, not some "no value".
In addition, NULL is the value of the field during LEFT JOIN if no matching row was found in the second table. Again - not a zero value, but its absence.

K
Kim_Maksim, 2020-01-06
@Kim_Maksim

I will add 1 more question: how is it different from None?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question