MySql and NULL

Discussion in 'Web Design & Coding' started by siLk, Jan 15, 2004.

  1. siLk

    siLk OSNN One Post Wonder

    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 ( "" ) ?
     
  2. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    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
     
  3. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    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 likes this.
  4. Khayman

    Khayman I'm sorry Hal... Political User Folding Team

    Messages:
    5,518
    Location:
    England
    Does it? thats pretty stupid, that was the whole point of NULL.
    Doesn't in any other SQL DBMS.
     
  5. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA

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

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    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
     
  7. siLk

    siLk OSNN One Post Wonder

    Messages:
    6
    ok, thanks for the info