Solved

SQLServer and VARCHAR(MAX) vs VARCHAR(8192)

Posted on 2011-04-28
9
868 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:MonCapitan
Comment Utility
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]
Comment Utility
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
Comment Utility
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
Comment Utility
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]
Comment Utility
unless you prove with tests to use VARCHAR(8000), I would go with the varchar(max) method.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

771 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

12 Experts available now in Live!

Get 1:1 Help Now