NULL or NOT NULL

Discussion in 'Databases' started by mahmood, Jun 20, 2006.

  1. #1
    What are the differences of a NULL column and NOT NULL?

    Which one do you think is better?
     
    mahmood, Jun 20, 2006 IP
  2. frankcow

    frankcow Well-Known Member

    Messages:
    4,859
    Likes Received:
    265
    Best Answers:
    0
    Trophy Points:
    180
    #2
    do you mean in the table definition? as in ALLOW NULL values?
     
    frankcow, Jun 20, 2006 IP
  3. rosytoes

    rosytoes Peon

    Messages:
    230
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It's not a question of which is better. It's rather a question of which is necessary. NOT NULL are used for primary keys.
     
    rosytoes, Jun 20, 2006 IP
  4. pelican

    pelican Active Member

    Messages:
    444
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    75
    #4
    it depends if that field is a required field. you definitely do not want NULL to be in a required field.
     
    pelican, Jun 20, 2006 IP
  5. infonote

    infonote Well-Known Member

    Messages:
    4,032
    Likes Received:
    68
    Best Answers:
    0
    Trophy Points:
    160
    #5
    According to what you want. In a recent site i made with Java and c#, i did not tick the not null in the db, but programmatically made it nexessary to include that field.
     
    infonote, Jun 21, 2006 IP
  6. ClearVisionDesigns.co.uk

    ClearVisionDesigns.co.uk Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You should always try and advoid having null fields in a database (bad design practice)

    specifiying a field as NOT NULL means when you insert a new record you will always have a value to fill that column. It allows the dabase system to optermise your database.
     
  7. iconv

    iconv Well-Known Member

    Messages:
    189
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #7
    Declaring NOT NULL also saves one bit on storage and makes indexes potentially more efficient.
     
    iconv, Jun 26, 2006 IP