The14thGOD Posted April 12, 2011 Share Posted April 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233443-help-clear-my-understand-my-understanding-of/ Share on other sites More sharing options...
requinix Posted April 12, 2011 Share Posted April 12, 2011 Blank != null. Are you sure those aren't empty strings? Quote Link to comment https://forums.phpfreaks.com/topic/233443-help-clear-my-understand-my-understanding-of/#findComment-1200387 Share on other sites More sharing options...
ignace Posted April 12, 2011 Share Posted April 12, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/233443-help-clear-my-understand-my-understanding-of/#findComment-1200414 Share on other sites More sharing options...
The14thGOD Posted April 12, 2011 Author Share Posted April 12, 2011 Ah, ok. Thanks, I got it now. Quote Link to comment https://forums.phpfreaks.com/topic/233443-help-clear-my-understand-my-understanding-of/#findComment-1200535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.