MySql and NULL

siLk

OSNN Newbie
Joined
Jan 13, 2004
Messages
6
#1
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
#2
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
#3
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
#4
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
#5
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
#6
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 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 ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
62,000
Messages
673,427
Members
89,025
Latest member
Haniew