Welcome to WebmasterWorld Guest from 54.221.30.139

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

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

In the MySQL table...

     

GreenLeaf

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

10+ Year Member



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.

jollymcfats

8:14 pm on Jan 27, 2005 (gmt 0)

10+ Year Member



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.

GreenLeaf

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

10+ Year Member



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.

mcibor

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

WebmasterWorld Senior Member 10+ Year Member



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

 

Featured Threads

Hot Threads This Week

Hot Threads This Month