Jump to content

Recommended Posts

NULL vs NOT NULL

I know it's been asked a billion+1 times but I'm more of trying to clear up my understanding of it....

Through countless searches/reading/books, what I seem to understand is:

NULL is on a field that can be left blank, 0 (if int), or NULL;

NOT NULL is on a field that can not be blank, 0 (if int) or NULL.

 

Yet in my databases all my fields are set to NOT NULL and I have blank fields... (this is where I'm confused)

Shouldn't I get an error saying that the field can not be NULL?

 

I have a big project I'm doing so I'm trying to make it so my db is running smoothly and one of the suggestions was make

sure all fields that can be are NOT NULL.

(I'm going to bed shortly so I may not respond till the morning...)

 

Thanks for any and all help.

Justin

NOT NULL literally means that it can't contain the special value NULL. NULL is not equal to '' (empty string) or 0 or anything else that makes the field empty. This special value is to indicate no value exists.

 

Your confusion comes from your experience with NULL from PHP where NULL == '' returns true as where MySQL returns NULL (everything compared to NULL is NULL, unless you specifically use IS NULL

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.