Solved

SQLServer and VARCHAR(MAX) vs VARCHAR(8192)

Posted on 2011-04-28
9
880 Views
Last Modified: 2012-08-14
Hi.
I am designing a database schema and I have question about VARCHAR. I have a field called ContentBody and it holds the content for a particular block on a page and the page is built from one or many of these blocks.

I don't know if the content editor of the site is going to insert more than 8192 bytes of data or less than 8192 bytes. (I am assuming at this point that VARCHAR(X) and VARCHAR(MAX) are my two options).

If I have VARCHAR(8192), a user will have to break up the content into many blocks, if the block is 20000 bytes say, which is not ideal which leaves me with VARCHAR(MAX). Some of the content might only be 100 bytes though and some maybe 20000 bytes or more.

With such a wide difference in number of bytes in this ContentBody field, what will I be doing to the database performance and size etc?

I hope this question makes sense and thank you for your time with this.

0
Comment
Question by:MonCapitan
9 Comments
 
LVL 22

Expert Comment

by:Om Prakash
ID: 35482275
If you are sure that data will not exceed 8000 then you can go for varchar otherwise you have to go with VARCHAR(MAX) .

With VARCHAR(MAX)  there will be performance issues in terms of  maintaining and reading the data.
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 35482295
if you can assume that at some point, the "block size" will be larger than the 8K, go with VARCHAR(MAX).
the performance issue mentioned above would only apply to those rows where the data actually goes over 8K
0
 

Author Comment

by:MonCapitan
ID: 35482414
Thanks for the replies.

How much of a performance difference. I mean, that is what VARCHAR(MAX) is designed for isn't it to hold lots of content?
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35482473
VARCHAR(MAX) is designed to combine the flexibility of the "small varchar(x)" and the capacity of the TEXT (2GB) data type.
yes, there is performance issue when you have to store/read/manipulate large data.
there is no performance issue for rows where the column data is "small" ...
0
 

Author Comment

by:MonCapitan
ID: 35482884
Thanks again angellll. Sorry for bashing this one out a bit but in my scenario, there will be only around 20-30 rows returned with each request that have the VARCHAR(MAX) field. Would that be truly significant on so negligible I shouldn't worry about it?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35482922
the only true answer will be: you have to test it out.
note that if you have to split up the rows into several rows, you will hence need to time the full process of reassembling the "splitted" rows

0
 
LVL 21

Expert Comment

by:Alpesh Patel
ID: 35483018
Varchar(X) - no of length you mentioned
Varchar(MAx) : 64000

Moreover, varchar occupy only those much of space as per the length of string. no as per the defined.
0
 

Author Comment

by:MonCapitan
ID: 35483033
Which won't take much overhead surely as I will be retrieving the rows, loading them into an object via a .NET DataReader and then reassembling them so most of the work is done at the application level.rather on the database server.

I also believe that 75% of the Rows will have less than 8000 bytes in the VARCHAR(MAX) field but of course, 25% will be over 8000.

Is this reasoning sound to you?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 35483069
unless you prove with tests to use VARCHAR(8000), I would go with the varchar(max) method.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
T-SQL: Episode III - Revenge of The Dude 24 52
sql server concatenate fields 10 31
Get the latest status 8 29
Query to capture 5 and 9 digit zip code? 4 20
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now