SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    column definition: NOT NULL DEFAULT NULL

    Hello!
    I've been using mysql for almost 10 years but never even thought about this
    commonly seen column definition:
    For example, column can be defined like this:
    'email_address char(100) NOT NULL DEFAULT NULL'

    Can someone exaplain this contradictory statement: how can the column be declared as NOT NULL and at the same type have a default value NULL?
    Isnt' NOT NULL mean that value cannot be NULL?
    Then how is it possible to have default value as NULL?

    I just never thought about it until today, now it's finally time to find the answer.

    I hope someone here can explain this really well. Thanks.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    695
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    It just means that if you do not supply a value for that column when doing insert, the DBMS will attempt to insert null which will cause an error. I.e. you are obliged to provide a non null value for that column when doing insert.

  3. #3
    PHP Guru lampcms.com's Avatar
    Join Date
    Jan 2009
    Posts
    921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, the NOT NULL DEFAULT NULL does not mean that if I don't provide a value, the NULL will be inserted, it means that if I don't provide a value there will be an error?

    I've never thought of this. I have to test it to make sure, but it does sound like reasonable explanation.
    My project: Open source Q&A
    (similar to StackOverflow)
    powered by php+MongoDB
    Source on github, collaborators welcome!


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
  •