Board index » delphi » Char or Varchar ?

Char or Varchar ?


2005-12-01 04:51:27 PM
delphi103
What is the difference between Char and Varchar ?
Is there any advantage to use varchar instead char ?
Thank you.
 
 

Re:Char or Varchar ?

Quote
What is the difference between Char and Varchar ?
CHAR is a logical format that pads spaces to the end
until it fills up the declared length.
So storing "yes" in a CHAR(10) column will end up
like this:
"yes "
when doing a SELECT.
Quote
Is there any advantage to use varchar instead char ?
VARCHAR doesn't pad spaces, so if you store
"yes", it will return "yes".
Varchar takes 2 bytes (or so) more space cause it has
to save the actual length of the data. So if you do a
boolean-like column with possible values Y, N ->then
use CHAR(1) (no spaces either way).
For the rest, I would use VARCHAR.
--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, Oracle & MS SQL
Server
Upscene Productions
www.upscene.com
Database development questions? Check the forum!
www.databasedevelopmentforum.com
 

Re:Char or Varchar ?

"Henry" <XXXX@XXXXX.COM>writes:
Quote
What is the difference between Char and Varchar ?
Is there any advantage to use varchar instead char ?

Thank you.


As I understand, varchar will store a variable length of
characters where char will store a set amount.
varchar(40) = 'Fred' = <stores 4 characters in file>
char(40) = 'Fred' = <stores 40 characters in file>
is this correct?