Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Default value for Foreign Key column, NULL or 0?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Devy  
View profile   Translate to Translated (View Original)
 More options 3 Nov, 22:36
Newsgroups: comp.databases.mysql
From: Devy <dev...@gmail.com>
Date: Tue, 3 Nov 2009 14:36:51 -0800 (PST)
Local: Tues 3 Nov 2009 22:36
Subject: Default value for Foreign Key column, NULL or 0?
This might be a trivial question. And I didn't find much of the
discussion after googling the topic. But I am still debating of
picking a default value for foreign key column to represent the non-
existence of such fk.

Is there any advantage between using NULL vs. using 0? What are the
pros and cons? What do you guys use as a convention?

Will using 0s reducing table size in terms of storage?

Thanks!!


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter H. Coffin  
View profile   Translate to Translated (View Original)
 More options 3 Nov, 23:08
Newsgroups: comp.databases.mysql
From: "Peter H. Coffin" <hell...@ninehells.com>
Date: Tue, 3 Nov 2009 17:08:29 -0600
Local: Tues 3 Nov 2009 23:08
Subject: Re: Default value for Foreign Key column, NULL or 0?

On Tue, 3 Nov 2009 14:36:51 -0800 (PST), Devy wrote:
> This might be a trivial question. And I didn't find much of the
> discussion after googling the topic. But I am still debating of
> picking a default value for foreign key column to represent the non-
> existence of such fk.

> Is there any advantage between using NULL vs. using 0? What are the
> pros and cons? What do you guys use as a convention?

Null's an *automatic* special case, that contaminate the specialness
to other operations automatically. 0 you have to code a lot of checking
for yourself. For example, null records cannot possibly join to
anything. A zero foreign key joins to any record that HAPPENS to end up
with a zero value in the referenced field, and if you default THAT to
zero as well, well... let's just say it's REALLY EASY to end up with a
lot of records that match that you don't want to.

> Will using 0s reducing table size in terms of storage?

Not by any appreciable amount. Disk is *cheap*.

--
62. I will design fortress hallways with no alcoves or protruding structural
    supports which intruders could use for cover in a firefight.
                --Peter Anspach's list of things to do as an Evil Overlord


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
toby  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 03:07
Newsgroups: comp.databases.mysql
From: toby <t...@telegraphics.com.au>
Date: Tue, 3 Nov 2009 19:07:16 -0800 (PST)
Local: Wed 4 Nov 2009 03:07
Subject: Re: Default value for Foreign Key column, NULL or 0?
On Nov 3, 5:36 pm, Devy <dev...@gmail.com> wrote:

> This might be a trivial question. And I didn't find much of the
> discussion after googling the topic. But I am still debating of
> picking a default value for foreign key column to represent the non-
> existence of such fk.

You should use NULL.
--------------------

For longer answer, see Peter's. :)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google