Re: char or varchar?
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 17 Sep 2007 14:39:10 -0400
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.
.
- Follow-Ups:
- Re: char or varchar?
- From: Marc Gravell
- Re: char or varchar?
- Prev by Date: Re: string.Empty
- Next by Date: Re: C# log component
- Previous by thread: Fast creation for huge DataGridView?
- Next by thread: Re: char or varchar?
- Index(es):
Relevant Pages
|