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
https://forums.phpfreaks.com/topic/34880-not-null-necessary/
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
https://forums.phpfreaks.com/topic/34880-not-null-necessary/#findComment-164468
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
https://forums.phpfreaks.com/topic/34880-not-null-necessary/#findComment-166712
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.