Re: char or varchar?



Jay,

Actually, when it comes to database operations, char fields are more
efficient, as the the character fields can be stored contiguously in memory,
and it is easy to get the data. With varchar fields, you have a redirection
in order to find the data, as the data can not be stored contiguously in
memory due to the changing size of the data.

Generally though, I wouldn't worry about this unless you have already
created your application and you know that this is a bottleneck.

As for what your ISBN numbers should be, if you are exposing the results
from the database directly without any processing, then I would say that the
varchar is better, as it return the data trimmed appropriately.

If there is a layer of indirection, then I would say to use char(13),
and then have the layer processing the data trim it before it is returned to
the user.


--
- Nicholas Paldino [.NET/C# MVP]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx

"Jay" <-> wrote in message news:%23OlrJQV%23HHA.5360@xxxxxxxxxxxxxxxxxxxxxxx
My understanding is that char stores a fixed number of characters even if
the string stored in the char has fewer characters, whereas varchar stores
the string with the number of characters that the string contains.

So, varchar sounds more efficient, but are there any disadvanages of using
varchar over char (eg speed and size)?

If I wish to store ISBNs (which can be 10 or 13 characters, using
characters
0-9 and X) would char(13) be a good choice? I don't need to store them as
unicode, so am ignoring nchar and nvarchar, but let me know if there are
any
problems with this.



.



Relevant Pages

  • Re: Char and Varchar
    ... If the maximum length is short (<= 10 characters), ... maximum length, I also use CHAR. ... I use VARCHAR if long and short ...
    (microsoft.public.sqlserver.server)
  • Re: Char and Varchar
    ... If the maximum length is short (<= 10 characters), ... maximum length, I also use CHAR. ... I use VARCHAR if long and short ...
    (microsoft.public.sqlserver.programming)
  • The Answer: (Was: TextBox Character Limit? (MS Access 2002 .adp connected to SQL))
    ... > to enter data in _other_ fields and use VB to concatenate other fields ... > into this 1024 char long field. ... it only shows the remaining text after the first 255 characters. ... The answer is that Access will not send more than 255 chars to a varchar, ...
    (microsoft.public.access.externaldata)
  • Re: text vs varchar vs image vs ?
    ... it is set to varchar. ... declare local variables of these types". ... I was sure 8000 characters would ...
    (microsoft.public.sqlserver.fulltext)
  • Re: ansi c
    ... Because the char type only stores single characters, ... Pointer types store locations in memory. ...
    (comp.lang.c)