MySql and NULL

siLk

OSNN Newbie
Joined
Jan 13, 2004
Messages
6
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 ( "" ) ?
 

Khayman

I'm sorry Hal...
Political User
Joined
Jan 6, 2002
Messages
5,518
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
 

X-Istence

*
Political User
Joined
Dec 5, 2001
Messages
6,498
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';
 

Khayman

I'm sorry Hal...
Political User
Joined
Jan 6, 2002
Messages
5,518
Does it? thats pretty stupid, that was the whole point of NULL.
Doesn't in any other SQL DBMS.
 

X-Istence

*
Political User
Joined
Dec 5, 2001
Messages
6,498
Khayman said:
Does it? thats pretty stupid, that was the whole point of NULL.
Doesn't in any other SQL DBMS.

I have always used it interchangeably with MySQL, like you said, no other ones do it.
 

Geffy

OSNN Veteran Addict
Joined
Mar 18, 2002
Messages
7,805
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 profile posts

Perris Calderon wrote on Electronic Punk's profile.
Hey ep!

All good with me, applying for microsoft mvp right now, should have done this a while ago.

Notifications don't work, I only found your response by comming back to hunt up some threads, if you want, give me your email address so we can keep in touch easier, mine is perriscalderon at gmail
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 https://tinyurl.com/ycpxl
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 ...

Forum statistics

Threads
61,976
Messages
673,274
Members
89,050
Latest member
lennerttt