473,405 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

char or varchar?

Jay
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.

Sep 17 '07 #1
5 2721
Can you expand on "redirection"? My understanding is that varchar is
still stored "in row"... but with a variable number of records per
page; the downside here being that this can necessitate page-shuffling
if the contents change and would overflow other records on the page
(exhausting the padding).

Marc

Sep 17 '07 #2
Sorry, I should elaborate. In the case of SQL Server 2005, if you have
a varchar type, then the data is stored in the field with a two byte prefix
indicating the length of the varchar string. However, if the size of the
row is greater than 8060 bytes, then SQL Server might store variable length
data off-row:

http://blogs.msdn.com/sqlserverstora...23/644607.aspx

varchar(max) is always stored off-row.

I'm not sure how it works in SQL Server 2000 and before though.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Marc Gravell" <ma**********@gmail.comwrote in message
news:11*********************@o80g2000hse.googlegro ups.com...
Can you expand on "redirection"? My understanding is that varchar is
still stored "in row"... but with a variable number of records per
page; the downside here being that this can necessitate page-shuffling
if the contents change and would overflow other records on the page
(exhausting the padding).

Marc

Sep 17 '07 #3
Although this is a bit old, it still should be helpful:

http://www.sql-server-performance.co..._space_p1.aspx
-- Peter
Recursion: see Recursion
site: http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com

"Marc Gravell" wrote:
Can you expand on "redirection"? My understanding is that varchar is
still stored "in row"... but with a variable number of records per
page; the downside here being that this can necessitate page-shuffling
if the contents change and would overflow other records on the page
(exhausting the padding).

Marc

Sep 17 '07 #4
varchar(max) is always stored off-row.
...
I'm not sure how it works in SQL Server 2000 and before though.
Well, [n]varchar(max) didn't exist, so you had either
[n]varchar(len<=8000) or [n]text. The former is in-row, the latter is
off-row by default, but short values can be brought in-row via
TEXT_IN_ROW, essentially the same as "row-overflow" in your cited doc;
with TEXT_IN_ROW specified, short values (your choice of length within
limits) can be brought in-row without any coding changes.

I've a suspicion (without any real grounds) that [n]varchar(max) can
work similar to TEXT_IN_ROW on [n]text.

Thanks for the info,

Marc

Sep 17 '07 #5
Jay
Thanks everyone for your answers - that was very helpful, as was the
discussion that followed.

Sorry about my very late reply...

Jay

"Jay" <-wrote in message news:%2******************@TK2MSFTNGP03.phx.gbl...
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.

Sep 21 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Randell D. | last post by:
Folks, I once read an article in Linux Format whereby a technical writer had made performance recommendations on a LAMP environment. One of the points raised was for small columns in a database,...
5
by: dmhendricks | last post by:
Greetings, I have a question. I work on some SQL2k/ASP.NET apps at work. My predacessor, who created the databases/tables seemed to have liked to use 'char' for all text fields. Is there a...
5
by: twkelsey | last post by:
Hi, My company has a scenario where we would like to change the data type of an existing primary key from an integer to a char, but we are concerned about the performance implications of doing...
10
by: Techie | last post by:
what's the difference of the two data types?
22
by: jdokos | last post by:
Hello, I have a question about VARCHAR fields. Our application groups here are starting to use VARCHARs much more frequently. Even VARCHAR (2) to (9) length fields. They say this is because...
1
by: Troels Arvin | last post by:
Hello, In the DBMS I know best, PostgreSQL, there is no real performance difference between CHAR and VARCHAR. And since CHAR pads with spaces, I generally dislike CHAR (with CHAR, it's not...
7
by: D. | last post by:
Hi, I'm planning the structure of a SqlServer 2005 database for a new application. The requirement is that primary keys must be "natural"; i.e. in the table Customers the primary key will be a...
0
by: Medhatithi | last post by:
I have a table whose indexed column is a char(16) field. I am giving the schema. CREATE TABLE Emp(Empno char(16), Ename varchar(25), ...
4
by: Nick Chan | last post by:
all these while i've only used varchar for any string i heard from my ex-boss that char helps speed up searches. is that true? so there are these: 1) char with index 2) char without index...
0
by: maheshmohta | last post by:
Background Often while remodeling legacy application, one of the important tasks for the architects is to have an optimum usage of storage capabilities of database. Most of the legacy applications...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.