IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

DEFAULT Clause


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
puneetvirmani143

New User


Joined: 24 Jul 2007
Posts: 55
Location: noida

PostPosted: Wed Oct 17, 2012 4:36 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Oct 17, 2012 4:44 pm
Reply with quote

icon_rolleyes.gif 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
View user's profile Send private message
puneetvirmani143

New User


Joined: 24 Jul 2007
Posts: 55
Location: noida

PostPosted: Wed Oct 17, 2012 7:21 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Oct 17, 2012 7:38 pm
Reply with quote

If you do not specify "NOT NULL" the default is null.
Back to top
View user's profile Send private message
puneetvirmani143

New User


Joined: 24 Jul 2007
Posts: 55
Location: noida

PostPosted: Wed Oct 17, 2012 7:50 pm
Reply with quote

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
View user's profile Send private message
GuyC

Senior Member


Joined: 11 Aug 2009
Posts: 1281
Location: Belgium

PostPosted: Wed Oct 17, 2012 8:01 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Running a Job with the Default User ID JCL & VSAM 2
No new posts To search DB2 table based on Conditio... DB2 1
No new posts Change Default Scroll Setting TSO/ISPF 1
No new posts Define default volume for DSN storage... JCL & VSAM 8
No new posts NOT IN clause in COBOL pgm COBOL Programming 8
Search our Forums:

Back to Top