Results 1 to 3 of 3
Dec 10, 2009, 07:51 #1
column definition: NOT NULL DEFAULT NULL
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.
Dec 10, 2009, 08:35 #2
- Join Date
- Jan 2004
- Uppsala, sverige
- 2 Post(s)
- 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.
Dec 10, 2009, 08:39 #3
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.