Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is difference between NULL and Empty in mysql

Tags:

mysql

What is difference between NULL and Empty String in Mysql ?

How much storage space it will take ?

For Example .

In the user table

name : NULL - How much space its take

phone : -How much space its take

like image 819
cHeE Avatar asked Dec 03 '09 15:12

cHeE


People also ask

What is difference between NULL and empty?

The Java programming language distinguishes between null and empty strings. An empty string is a string instance of zero length, whereas a null string has no value at all. An empty string is represented as "" . It is a character sequence of zero characters.

Is NULL or empty in MySQL?

The IS NULL constraint can be used whenever the column is empty and the symbol ( ' ') is used when there is empty value. mysql> SELECT * FROM ColumnValueNullDemo WHERE ColumnName IS NULL OR ColumnName = ' '; After executing the above query, the output obtained is.

Is it better to use NULL or empty string?

So it is better to use empty string for database as allowing NULL value forces the system to do extra work and does not give the data that you are looking for. However, NULL does not throw any exception when the count() function is executed.

What is the difference between NULL zero and blank?

NULL means it does not have any value not even garbage value. ZERO is an integer value. BLANK is simply a empty String value.


1 Answers

The best way to think about NULL is that it is poisonous.

Any operation done with NULL will produce NULL.

NULL + any number type is null. NULL concat any string is null.

An empty string is a string with length of 0.

Example:

mysql> select concat('hello world', null);
+-----------------------------+
| concat('hello world', null) |
+-----------------------------+
| NULL                        |
+-----------------------------+

mysql> select concat('hello world', '');
+---------------------------+
| concat('hello world', '') |
+---------------------------+
| hello world               |
+---------------------------+

As for space saving it depends on the datatype the column is defined.

like image 71
Yada Avatar answered Sep 30 '22 16:09

Yada