MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Choose Between VARCHAR and CHAR

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Tue Apr 19, 2005 2:25 pm    Post subject: Choose Between VARCHAR and CHAR Reply with quote

I am creating a table with these columns:
Code:

  ColA CHAR(9)
  ColB Date
  ColC Time
  ColC CHAR(50)
  ColD CHAR(50)
  ColE CHAR(80)
  ColF VARCHAR(600)

I read that it is more efficient to use CHAR than VARCHAR if the number of characters is small. I am not sure what is consider as small. Since ColC, D and E will contain data from 5 characters to 80 characters, is it better to define as VARCHAR or leave as CHAR?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12372
Topics: 75
Location: San Jose

PostPosted: Tue Apr 19, 2005 2:49 pm    Post subject: Reply with quote

danm,

In general VARCHAR data types should be used for columns containing long descriptions or memos that are not referenced very often. 50 bytes is probably the smallest length you would want to use for a VARCHAR column. DB2 does have to allocate some additional bytes for each row with variable length columns to keep track of the varying length data, so some of the space savings will be consumed by these "extra tracking" bytes. Due to this overhead, the space savings would only be noticeable on tables with a large number of rows.

Fcators to Consider in deciding between Varchar and Char.

1.The amount of variability must be considered. A column that only varies between 8 and 10 bytes does not generate any savings whereas a column that has 95% of its values at 10 bytes and the other 5% at 100 bytes would generate great savings. The bottom line is Greater variability provides greater incentive to use Varchar.

2.Carrying extra bytes by using a Char instead of Varchar can produce the following cons


  • Additional space requirements for both table and any indexes containing the column.

  • Larger rows mean fewer rows per page, which means fewer rows delivered for each physical read, including when prefetching.

  • Larger rows mean increased sort costs and memory requirements when querying the column.

  • Larger rows mean fewer rows can be in the bufferpools, reducing buffer hit ratios.

  • Larger columns mean increased costs in delivery of result sets.

  • Larger columns mean increased costs when using the column as a local or join predicate since more bytes have to be compared.


Hope this helps...

Cheers

kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
danm
Intermediate


Joined: 29 Jun 2004
Posts: 170
Topics: 73

PostPosted: Tue Apr 19, 2005 3:35 pm    Post subject: Reply with quote

Kolusu and Ravi,

Thanks.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group