2

whenever we create our table in mysql database then a option of null checkbox is present there. and if click it then also it takes the null value and if it remains unchecked then also it takes null values. What is the meaning of that?

1
  • Sounds like whatever you're using to create your tables isn't working correctly. If you define a table as NOT NULL, then you can't store NULL in it. Either that or you're storing the string value 'null' and not an actual NULL. Do SHOW CREATE TABLE table; and check the definition. Commented Sep 7, 2012 at 17:57

4 Answers 4

3

NULL is used to represent "no value" and allow that to be distinguished between 1 and 0, true or false, or an empty string versus a string with content. It's similar to nil in Ruby, null in JavaScript or NULL in PHP.

If you define a column as NOT NULL then it won't allow an INSERT without a value for that column being specified. If you have a DEFAULT then this will be applied automatically. If you use an ORM it may fill it in for you with a safe, minimal default.

Columns that can be NULL require an almost insignificant amount of additional storage per row, one bit, to hold the NULL or NOT NULL flag.

Remember that NULL in MySQL is unusual in that it is not greater than, less than, or equal to any other value. This is why IS NULL and IS NOT NULL are required for logical comparisons.

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

Comments

1

The checkbox probably sets the default value to null. There may also be a box that specifies whether or not the field accepts null values. Null basically means Empty or Nothing (in VB).

Comments

0

Null is basically "no value". If you allow nulls, you need to ensure that your code is able to handle that column not containing a value. Another approach is a defined "empty" value for each column (e.g. 0 for an integer). This can sometimes be less effort than handling a null value.

As noted by HLGEM below: I'm not trying to say 0 is equivalent to null. Consider: DB with "StockOnHand" column.

0 means you know there is no stock on hand. Null really means unknown (you man have stock, you may not)

Depending on the application, perhaps you decide to treat "unknown" the same as "no stock" - in this case you could use "no nulls" and just have a 0 value.

1 Comment

However, 0 has a specific mathmatical meaning and is no way comparable to null which means you do not know the value. There may be times when you can do this if you do not know the value but it is a dangerous practice.
0

According to the manual:

The NULL value means "no data." NULL can be written in any lettercase. A synonym is \N (case sensitive).

NOT NULL would mean the opposite of NULL, or not no data. Since some columns can be NULL, you use WHERE col IS NOT NULL to find values that are not "empty."

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.