+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 13

Thread: Whats preferable in field - null or empty?

  1. #1
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Whats preferable in field - null or empty?

    Hi people
    I was wondering if Null values should be allowed in db fields or not?

    I dont allow Null values in database, i enter "empty" rather than Null.

    But i think when there is a large amount of data/records, then these "empty" entries might add to db size/burden.

    Right now, i insert "empty" for text fields, 0 as default for integer/float types and always some value in datetime fields.

    Your thoughts please
    Thanx

  2. #2
    Moderator don94403 is a jewel in the rough don94403 is a jewel in the rough don94403 is a jewel in the rough don94403's Avatar
    Join Date
    Mar 2008
    Location
    San Mateo, CA, USA
    Posts
    313
    Blog Entries
    8
    Real Name
    Don Ravey
    Rep Power
    6

    I don't see any particular advantage to substituting a word like "empty" in place of a Null value, at least in general. I can imagine some particular application where that might help to call attention to missing data, but operationally, there is usually no penalty to just leaving a field Null. It does mean, though, that you have to keep in mind the possibility of retrieving a Null value from the database, so you can't use logic that depends on finding an actual value. I think it's good practice to always protect against a Null value crashing your logic, anyway.

    For numeric fields, I would say that it depends on the significance of a field having no initial value. Well, that's true for any other data type, too, of course. If you need to make a distinction between missing data and data that is deliberately blank, then you need to start with Nulls. For example, if you have an accounting application with balances outstanding, it makes a difference whether an account is known to have a zero balance or whether there is no information on whether there's a balance or not.

  3. #3
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Thanx don
    I dont enter the word "empty"....... i just enter "" (sorry, i didnt explain it well), meaning the value in column is empty, not null

    I was just asking in terms of database advantage/disadvantage
    Last edited by micky; June 8th, 2009 at 05:01 AM.

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    M,

    This is one of those heavily debated topics. Have a look at this blog (particularly all the comments): Why NULL Values Should Not Be Used in a Database Unless Required

    It is my opinion that NULL has its place in database design. Keep in mind that NULL means Unknown, whereas an empty string means that it is Known, but not entered as a value. I personally avoid using NULL. In fact, the database in my current project is designed to not accept NULL. Supposedly, NULL takes less space than an empty string, but I'm not sure how much you're actually saving.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    My opinion too J
    I also avoid NULL values in my database structure nad never enter null in database.

    I'll read the blog for more

  6. #6
    Wolfmaster Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy is a splendid one to behold Wolffy's Avatar
    Join Date
    Mar 2008
    Location
    Peoria, IL
    Posts
    2,386
    Blog Entries
    5
    Real Name
    Wolff
    Rep Power
    15

    In MS SQL, a null value takes no space -- rather a NULL bit is set in the record header or the field. If you have a table with no null field, you'll save this 8-bit field, otherwise, you can have up to 8 null fields with no penalty.

    Storing an empty string in a variable length field takes at least 2-bytes for the length. If you have millions of records, this could be significant.

    NULLS do have their place tho -- if the data they represent is optional, such as a ShipToAddress, then NULL seem appropriate since it accurately represents that no data was supplied. However, I agree that NOT NULL should be the default unless you have a very good reason to make the field NULLable
    Wolffy
    .-- ----- ..-. ..-. -.--
    Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Void where prohibited by law. Not valid in California. Your mileage may vary.

  7. #7
    I like Data Cubes too... Lauramc has a spectacular aura about Lauramc has a spectacular aura about Lauramc's Avatar
    Join Date
    Mar 2008
    Location
    Far Far Away
    Posts
    387
    Real Name
    Laura
    Rep Power
    5

    I think NULL should be used when it's appropriate as you all have mentioned. It indicates when a value is intentionally blank, and that can be very useful.

    My shop has another reason to allow nulls. Our in-house software has its' own persistence model that requires it to understand the schema of the database. Basically it's an XML schema. If a change is made to the SQL server schema before the code is updated, the application would fail unless the new field allows null. However, the database update MUST occur before the code is deployed or it would fail because of the missing columns... it's a chicken and egg scenario. The only way to add a NOT NULL column to our production database is to create the column as nullable, update the data to the default and then update the column to NOT NULL.

    As Don said, it's probably good practice to write your code with the possibility of nulls being considered. As for me, I use the NULLS to my advantage. It's easy to eliminate them
    "The Enrichment Center is required to remind you that first you will be baked, then there will be cake." - GLaDOS

  8. #8
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Thanx Wolffy and Laura
    I am not worried about handling Null, but i was more concerned about the database space utilization difference between Null and empty string.......... which for say thousands of records wont be much (right?).

    Anyway, i think i can live with Empty strings in db rather than Null as of now.

  9. #9
    Super Sarcasm Mistress mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere is a glorious beacon of light mehere's Avatar
    Join Date
    Mar 2008
    Location
    Wide Awake In Dreamland
    Posts
    830
    Rep Power
    8

    okay ... i'm thinking i shouldn't take classes, but just as a point of fact, null values are considered in calculating storage requirements if the field is a fixed length datatype such as int, char, money, etc. it is not included, however, when using varchar. for example ... if you have 10 columns in your db and they are all fixed length datatypes, you would have to account for 2B of space. although minimal, it is still counted.

    see ... i am learing some things.

    btw ... empty strings take up more space than null values.
    Last edited by mehere; June 9th, 2009 at 10:04 AM.
    Quote of the Month:
    INSIGHT: When the going gets tough, the tough get going. The smart left a long time ago.

    Questions to Ponder:
    Are people more violently opposed to fur rather than leather because it's much easier to harass rich women than motorcycle gangs?

    iif([sarcasm]=true,iif([you have to ask]=true,"didn't work","ha ha ha"),"not sarcasm")
    copyright © 2008 sbenj69

    Sarchasm: The gulf between the author of sarcastic wit and the person who doesn't get it.

  10. #10
    Lazy Bum micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky is a jewel in the rough micky's Avatar
    Join Date
    Jul 2008
    Location
    India
    Posts
    1,763
    Blog Entries
    2
    Rep Power
    8

    Quote Originally Posted by mehere View Post
    btw ... empty strings take up more space than null values.
    Ya, i sensed it

    Thats the reason i raised this issue.
    So i am still not sure of allowing Nulls in database

+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. validate empty textbox js
    By tulz in forum JavaScript Programming
    Replies: 1
    Last Post: February 11th, 2009, 06:13 AM
  2. show datagrid even if empty
    By micky in forum .NET Development
    Replies: 3
    Last Post: December 9th, 2008, 08:39 AM
  3. Replies: 3
    Last Post: November 18th, 2008, 03:16 AM
  4. Field that is a link (rs) and/or text field question
    By Rebelle in forum ASP Development
    Replies: 14
    Last Post: August 12th, 2008, 09:43 AM
  5. Replies: 8
    Last Post: June 17th, 2008, 10:39 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO