SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot sethtrain's Avatar
    Join Date
    Dec 2003
    Location
    Paducah, KY
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    NULL vs. NOT NULL

    Which is better? Using the setting NOT NULL and providing a value in the web application or using NULL and not providing the value.
    --
    sethtrain

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That depends. What are you trying to accomplish? Do you understand nulls and why they are used?

    Basically using NULLS means that you can have an absence of values. If you are keeping a record of test scores for instance, and can have students who have not written the tests then you would want to use NULLS in that field. If you entered any other value that would be wrong. So for instance if you used NOT NULL and entered a value of 0 or 99999 (an impossible score for instance) to represent someone not taking the test both of those would technically be incorrect.

  3. #3
    SitePoint Zealot sethtrain's Avatar
    Join Date
    Dec 2003
    Location
    Paducah, KY
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I will be using should always have a value and the reason I ask this is because I could make NOT NULL and have the database send the error if the value isn't included or build in the validation myself. I didn't know what would be correct.
    --
    sethtrain

  4. #4
    SitePoint Guru
    Join Date
    Aug 2003
    Location
    CT
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    leaving a field as NULL is there for a reason.
    If data is not required, don't put something in it.

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by sethtrain
    What I will be using should always have a value
    in that case, make it NOT NULL

    feel free to use NOT NULL with DEFAULT, in which case you don't have to submit the value at all

    with NOT NULL but no DEFAULT, it will bomb if you don't supply the value

    make sure it isn't a phony value, though
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •