Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 Just how much overhead does a varchar column introduce?

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-05-20 : 08:29:53
Martin Binder writes "I'm trying to determine the record size of a SQL table. I have a field that is a varchar(20), let's say. I know that when storing the actual data, SQL Server will only use up however many bytes the column is comprised of. What I want to know is what is the overhead of using a varchar field? I've been from one end of Google to the other searching for the answer to this with varying results. Some people say there is a two byte overhead per varchar field. Other people say it's 4 bytes. Still other people say it's 4 bytes for the first varchar field, and 1 byte per additional varchar field.

Can you please make sense of this all? I would greatly appreciate it, thanks!"

efelito
Constraint Violating Yak Guru

478 Posts

Posted - 2002-05-20 : 11:55:06
There is a good run down of how this works in on page 232 of Inside Microsoft SQL Server 2000 by Kalen Delaney. If you more answers to indepth questions like this you should really pick up this book.

Every row has a 10 byte overhead.
Every varchar field has a 2 byte overhead
There is a 2 byte overhead for a row with a varchar field.

So, in the following example, the maximum row size would be 66. 50 for the actual column lengths, 12 for the row itself (because it contains varchar fields), and 4 for the varchar fields.

CREATE TABLE dbo.mytable (
COL1 VARCHAR(20),
COL2 VARCHAR(20),
COL3 CHAR(10)
)

HTH

Jeff Banschbach
Consultant, MCDBA
Go to Top of Page
   

- Advertisement -