Jump to content

NOT NULL necessary??


Rayben

Recommended Posts

Hi!
I've been working with MySQL for a few months now with the help of online tutorials
and I've noticed that everyone allways sets columns to NOT NULL. Why is that?
I can't see any reason to do that in general. However, being a semi-noob I get a little nervous from time to time
thinking that I've missed something about this NOT NULL property that will come back and bite me in the butt just as
I completed a major project.

Any comments? Or can I just skipp "NOT NULL"'ing stuff?
Link to comment
Share on other sites

Keep in mind that NULL is truly nothing, whereas "" is an empty string.

NULLs are useful for fields that are not required. For example, if your table has a foreign key constraint, but a relationship is not required, you cannot use "" or 0: the field has to be NULL.
Link to comment
Share on other sites

Unless you need NULL, don't bother having it... I really need to write a sticky on this topic, I keep answering it over & over again (but not recently enough, apparently).  If you don't have to distinguish between blank/zero and "nothing", like effigy said, then no, you don't need it.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.