View previous topic :: View next topic
|
Author |
Message |
puneetvirmani143
New User
Joined: 24 Jul 2007 Posts: 55 Location: noida
|
|
|
|
I have a field in DB2 table defined as :
FSA_INDICATOR CHAR(1) WITH DEFAULT
Will this field contain NULL or SPACE when the field value is not supplied considering the DEFAULT Clause ?
Regards
Puneet |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
open a manual!
SQL Reference for example, look up the statement CREATE TABLE , find the explanation on the clause WITH DEFAULT and it says :
Quote: |
If a value is not specified after DEFAULT, the default value depends on the data type of the column, as follows: |
I did it, now go do it yourself . |
|
Back to top |
|
|
puneetvirmani143
New User
Joined: 24 Jul 2007 Posts: 55 Location: noida
|
|
|
|
I was also under the same impression. But the field also contains NULLs here. Thatwhy i wanted to know opinion of others.
Does it also depend on DB2 version ?
Regards
Puneet |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
If you do not specify "NOT NULL" the default is null. |
|
Back to top |
|
|
puneetvirmani143
New User
Joined: 24 Jul 2007 Posts: 55 Location: noida
|
|
|
|
Do you mean to say
1. FSA_INDICATOR CHAR(1) WITH DEFAULT
OR
2. FSA_INDICATOR CHAR(1)
both 1) and 2) actually mean the same that incase data is not supplied it will contain NULL.
Regards
Puneet |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
Actually Craq it is NOT.
null is only the default when you do not speciy "NOT NULL" AND not specify "WITH DEFAULT".
or ofcourse specify "WITH DEFAULT NULL"
as you can see from below test :
Code: |
create table testnul
(
Keycol char(1),
co1 char(1) not null with default 'X',
co2 char(1) not null with default ,
co3 char(1) not null ,
co4 char(1) with default 'X',
co5 char(1) with default ,
co6 char(1) with default NULL,
co7 char(1)
)
;
insert into testnul (Keycol,co3) values ('A','a')
;
select * from testnul
;
drop table testnul
;
|
(you have to specify co3 on the insert, because that's what NOT NULL without DEFAULT does)
result :
Code: |
co1='X'
co2=' '
co3='a'
co4='X'
co5=' '
co6=<NULL>
co7=<NULL> |
|
|
Back to top |
|
|
|