Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2008
    Location
    Toronto,Canada
    Posts
    655

    Unanswered: 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

  2. #2
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

  3. #3
    Join Date
    Dec 2007
    Location
    Richmond, VA
    Posts
    1,328
    Provided Answers: 5
    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

  4. #4
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    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

  5. #5
    Join Date
    Sep 2008
    Location
    Toronto,Canada
    Posts
    655
    Thanks All

    DBFinder

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •