MySql and NULL


OSNN Newbie
When checking the database to see if a value has been inserted into a field marked NULL do you actually check it as NULL or do you check it as an empty string ( "" ) ?


I'm sorry Hal...
Political User
an empty string is not a NULL. if its NULL then it needs to be checked as NULL. If you've inserted it as a blank string the it is not null


Political User
NULL and a blank string are basically the same thing in MySQL Khayman, they both mean the field is empty, and both will suffice.

So this:

SELECT * FROM table WHERE string = '';

is the same as

SELECT * FROM table WHERE string = 'NULL';


OSNN Veteran Addict
as no others do it, then probably better to use the version with NULL in it as it will make your code more portable should you want to change your RDBMS to something else, also makes learning the syntax or getting used to the syntax of other RDBMS's a slight bit easier

Members online

No members online now.

Latest posts

Latest profile posts

Perris Calderon wrote on Electronic Punk's profile.
Ep, glad to see you come back and tidy up...did want to ask a one day favor, I want to enhance my resume , was hoping you could make me administrator for a day, if so, take me right off since I won't be here to do anything, and don't know the slightest about the board, but it would be nice putting "served administrator osnn", if can do, THANKS

Been running around Quora lately, luv it there
Electronic Punk wrote on Perris Calderon's profile.
All good still mate?
Hello, is there anybody in there? Just nod if you can hear me ...
What a long strange trip it's been. =)

Forum statistics

Latest member