If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Which is better - VARCHAR(20) or CHAR(20)

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-03-09, 11:29
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Which is better - VARCHAR(20) or CHAR(20)

Hi all,

Which is better - VARCHAR(20) or CHAR(20) -- for indexing and speed

This is going to be a primary key.

Thanks
DBFinder
Reply With Quote
  #2 (permalink)  
Old 03-03-09, 16:56
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Depends on the average size of your varchar. There is a slight CPU overhead on processing a varchar, but it could use less memory and have more index rows per page (but don't forget about 2-byte overhead on varchar to store the length).
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #3 (permalink)  
Old 03-04-09, 10:42
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
To be honest I prefer to use a fixed length char field over a verchar. They make copying data around much easier. As when you have a varchar you can't run a simple
insert into mytesttable select * from myprodtable where condtions apply
At least not on Z/OS, its been awhile since I worked on LUW so I'm not sure over there.

Dave
Reply With Quote
  #4 (permalink)  
Old 03-04-09, 10:56
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
Quote:
Originally Posted by dav1mo
To be honest I prefer to use a fixed length char field over a verchar. They make copying data around much easier. As when you have a varchar you can't run a simple
insert into mytesttable select * from myprodtable where condtions apply
At least not on Z/OS, its been awhile since I worked on LUW so I'm not sure over there.

Dave
The insert works fine on LUW.

Andy
Reply With Quote
  #5 (permalink)  
Old 03-04-09, 19:39
DBFinder DBFinder is offline
Registered User
 
Join Date: Sep 2008
Location: Toronto,Canada
Posts: 606
Thanks All

DBFinder
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On