Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

DEFAULT Clause

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: DEFAULT Clause
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: 1278
Location: Belgium

PostPosted: Wed Oct 17, 2012 4:44 pm    Post subject:
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    Post subject: Reply to: DEFAULT Clause
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    Post subject:
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    Post subject:
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: 1278
Location: Belgium

PostPosted: Wed Oct 17, 2012 8:01 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Need help on SQL Dynamic WHERE Clause subratarec DB2 12 Sat Jul 16, 2016 3:11 pm
No new posts force windows ftp client user to defa... meykh2014 All Other Mainframe Topics 0 Sun Feb 14, 2016 12:57 pm
No new posts change z/os default 1047 ccsid tp 1097 meykh2014 All Other Mainframe Topics 4 Sat Sep 05, 2015 5:21 pm
No new posts [SQL0029] INTO clause missing from em... HABBIE DB2 2 Fri Sep 04, 2015 3:54 pm
No new posts 3-D Table with nested DEPENDING ON Cl... VivekKhanna COBOL Programming 5 Sat Aug 08, 2015 11:18 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us