Answer the question
In order to leave comments, you need to log in
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
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.
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.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question