1

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

1
  • 1
    Because there no EMPTY in INT - it is NULL instead Commented Mar 10, 2011 at 14:36

3 Answers 3

8

Because there's a semantic difference between NULL and empty.

If a field is empty, how can you tell the difference between the following?

  1. the value is known to be empty
  2. the value is unknown

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.