Welcome to WebmasterWorld Guest from 54.221.9.209

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

What is better as a default value: NULL or ''?

In the MySQL table...

     
7:59 pm on Jan 27, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 10, 2003
posts:161
votes: 0


I would like to collect some statistical data and then make some reports on it. I'm creating tables for this task and i'm not sure what is better for filling default values: NULL or ''. What is optimal for storage purposes and for further reports creation?
Thanks in advance.
8:14 pm on Jan 27, 2005 (gmt 0)

Full Member

10+ Year Member

joined:Mar 3, 2004
posts:270
votes: 0


If you're willing to make the slight extra effort to use & handle NULL, it is a better choice for a not-present value because it provides you with additional information about why the field is blank.

Often NULL is used to mean "A value isn't available" and the empty-string '' means "There is a value, and it is empty." Subtle difference, but often critical for things like reports.

11:34 pm on Jan 27, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Feb 10, 2003
posts:161
votes: 0


I remember to have problems with NULL in UNION statements like

select something, null, ...
union all
select null, something2, ...

What are the rules to make these queries right?
Thanks a lot.

3:12 pm on Jan 28, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 26, 2003
posts:1133
votes: 0


You can't select null. you can only select columns and null is a keyword (the same as order or date).

To select null values you need to pass:

SELECT bla WHERE bla IS NULL;

If not null then:

SELECT bla WHERE bla IS NOT NULL;

You cannot use bla = NULL - this is wrong!

Best regards
Michal Cibor