SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Regarding using VARCHAR(MAX)


Regarding using VARCHAR(MAX)

Author
Message
surendra.babu
surendra.babu
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 21
Hi All,

I would like to know whether the usage of VARCHAR(MAX) intead of using VARCHAR(fixedlength) affects the performance.

Thanks in Advance!!!

with regards,

S.N.Surendrababu
ChiragNS
ChiragNS
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3439 Visits: 1865
Varchar(fixedlength) has maximum capacity of 8000. i.e you can define varchar(8000). If you want to store more than this in a varchar column you need to use varchar(max). The maximum capacity of varchar(max) is 2gb.
Use varchar(max) only when its required.


check this out for more details -
http://www.sqlserverandxml.com/2008/01/varcharnvarchar-n-vs-max.html


"Keep Trying"
jezemine
jezemine
SSC Eights!
SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)SSC Eights! (809 reputation)

Group: General Forum Members
Points: 809 Visits: 589
one drawback is that varchar(max) can't form part of a index key.

also it's simply wasteful and inefficient.

when you write a program in C, you don't allocate 2gb of memory to hold a 10 character string do you?

---------------------------------------
elsasoft.org
ChiragNS
ChiragNS
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3439 Visits: 1865
True varchar(max) cannot be a part of a index. But it has its uses. Its much easier to store and manipulate large strings compared to sql server 2000.

"Keep Trying"
surendra.babu
surendra.babu
Forum Newbie
Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)Forum Newbie (4 reputation)

Group: General Forum Members
Points: 4 Visits: 21
Hi,

I use VARCHAR(MAX) for parameters (Not for fields), These parameters are used in the Where clause of the Query.

for example.


CREATE PROCEDURE [Sample]
(
@deliverycenter varchar(500)
)

as

declare
select * from itemdetails i where i.deliverycentercd in (@deliverycenter)
.....

Here instead of using varchar(500) can I use VARCHAR(Max), does it affects the performance.
er.soundararajan-800293
er.soundararajan-800293
Valued Member
Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)

Group: General Forum Members
Points: 53 Visits: 30
Hi there,

If you are sure that the length of the parameter @deliverycenter will be less than 8000 characters then use varchar(500). Whilst varchar(MAX) will not affect the performance much, since they are stored in the database memory space rather than a pointer to data concept as in Sql Server 2000 (TEXT/NTEXT/ IMAGE datatypes). So the process time with varchar(MAX) is proportional to the size of the data you are processing . (Will not be of much difference).
So the answer to your question is "The performance will not be affected much".



declare
select * from itemdetails i where i.deliverycentercd in (@deliverycenter)

I don't understand why you using the above syntax, instead you can use a direct comparison to compare two strings.(here you are trying to perform a case sensitive compare between @deliverycenter and i.deliverycentercd).
ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12318 Visits: 8928
Rowsize > 8060 bytes ?
-table size is still limited by fixed-length types, as well as internal headers and row pointers.
-You cannot create a table with a row size of greater than 8060 bytes if that table is comprised of e.g. all numeric columns.
row overflow:
-If a row exceed 8060 bytes, the data for varying columns (VARCHAR, NVARCHAR, or VARBINARY) will be automatically moved off-row into the large object area.
In addition, each column that is moved off-row will occupy a 24-byte on-row pointer. Make sure when creating large tables that the pointers will not cause rows to overflow the 8060-byte limit, or data modifications may be terminated as a result of too much data in row.

If you have off-row columns, you may end up with vast IO overhead.
(One to read the pointer, the second to read the off-row column)

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
er.soundararajan-800293
er.soundararajan-800293
Valued Member
Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)Valued Member (53 reputation)

Group: General Forum Members
Points: 53 Visits: 30
Ya you are right, that above for 8000 bytes we need a off row data, we should also turn on the option "large value types out of row". But i wonder what is the big difference between the TEXT and VARCHAR(max) apart from the fact that VARCHAR(MAX) can be used as local variables whereas TEXT cannot be so.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)SSC Guru (88K reputation)

Group: General Forum Members
Points: 88268 Visits: 45277
TEXT is an older datatype, is deprecated in SQL 2005 and will be removed in a future version. Many of the string functions (left, right, substring, replace, etc) don't work on Text, while the do on varchar(max)

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


ALZDBA
ALZDBA
SSChampion
SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)SSChampion (12K reputation)

Group: General Forum Members
Points: 12318 Visits: 8928
The huge advantage of varchar(max) compared to Text is you no longer need to use the special functions to manipulate text-columns, you can use them as variables, parameters, ...

Johan


Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere w00t

- How to post Performance Problems
- How to post data/code to get the best help


- How to prevent a sore throat after hours of presenting ppt ?


press F1 for solution, press shift+F1 for urgent solution :-D


Need a bit of Powershell? How about this

Who am I ? Sometimes this is me Alien but most of the time this is me Hehe
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search