homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

db field default value: none vs null

Msg#: 4329368 posted 2:04 pm on Jun 22, 2011 (gmt 0)

Hi there,

I just have one little question. I'm using phpMyAdmin to set up a database and I was wondering, what is the difference between setting a field's default value to none and setting it to null? what are the benefits/disadvantages of each? and how do they relate to php? (for example if i'm pulling records from the db and testing the returned values with isset, what does null vs none return?) if there is a comprehensive answer to this question out there somewhere already, i missed it, so here i am asking :-)



WebmasterWorld Senior Member demaestro us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4329368 posted 2:41 pm on Jun 22, 2011 (gmt 0)

I don't think 'none' is a value you can give. Unless it is the string 'none'.

If you by 'none' you mean an empty string, then there are differences, but they are subtle.

The best way to explain it is like this, if you insert a row into your table and you don't specify a value for a column then it's value will be null.

Null works for all data types, boolean, string, integer and so on. Where as an empty string won't work in an integer field, and 0 won't work in a string field, although '0' would.

Typically you will see a lot of queries checking for both.

select * from table where StrField is not null and != ''


select * from table where IntField is not null and != 0

I wouldn't say one has an advantage over another but I would say be consistent throughout your application.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved