0

Best practice mysql NULL or not ?

http://stackoverflow.com/questions/1267999/mysql-better-to-insert-null-or-empty-string

 

 

I Personally use NULL for more powerful results..

 

By using NULL you can distinguish between “put no data” and “put empty data”.

Some more differences:

A LENGTH of NULL is NULL, a LENGTH of an empty string is 0.

NULLs are sorted before the empty strings.

COUNT(message) will count empty strings but not NULLs

You can search for an empty string using a bound variable but not for a NULL. This query:

SELECT *
FROM mytable
WHERE mytext = ?
will never match a NULL in mytext, whatever value you pass from the client. To match NULLs, you’ll have to use other query:

SELECT *
FROM mytable
WHERE mytext IS NULL

facebooktwittergoogle plus


Leave a Reply