Reputation: 62394
Why would you default a field to NULL instead of just leaving the value empty? Is it merely so you can query IS NULL
?
I'm specifically asking about INT
or other numerical data types
Upvotes: 1
Views: 4027
Reputation: 61437
Define "leaving the value empty". An empty value is null. If you mean empty = 0, then think about an account (money wise). You can have an account with 0$ in it, but you also can have no account at all (null). There is a difference between 0 and null.
Upvotes: 1
Reputation: 269388
Because there's a semantic difference between NULL
and empty.
If a field is empty, how can you tell the difference between the following?
That's what NULL
is for: if you don't know the value then use NULL
; if you know the value -- empty or not -- then use it.
Upvotes: 8
Reputation: 26597
There's no such notion as "empty" in MySQL.
For example, an int column is either an integer, or NULL.
If you don't specify a default value for your int column, if you try to insert a new row without specifying something for this column, mysql will raise an error.
Upvotes: 2