473,395 Members | 1,783 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,395 software developers and data experts.

Performance question concerning varchar(max)

SQL Server 2005
Simple scenario - We want to store answers to survey questions. Some
questions require very short responses (one or two words) while others
require long essay type responses.

--Scenario 1 -- store all answers in one column, regardless of
question
CREATE TABLE Answers
(
AnswerID int identity PRIMARY KEY,
UserID int,
QuestionID int,
AnswerText varchar(max)
)

--Scenario 2 -- store answers to short questions in one column and
long ones in another
CREATE TABLE Answers
(
AnswerID int identity PRIMARY KEY,
UserID int,
QuestionID int,
ShortAnswerText varchar(50),
LongAnswerText varchar(max)
)

Assume an index on QuestionID

If we need to query the table as in Scenario 1 for short question 27
as in

SELECT UserID, AnswerText
FROM Answers
WHERE QuestionID = 27 And AnswerText Like '%headache%'

Will we suffer a performance penalty vs. querying Scenario 2 as in

SELECT UserID, ShortAnswerText
FROM Answers
WHERE QuestionID = 27 And ShortAnswerText Like '%headache%'

I would think that the optimizer would first use the index on
QuestionID and this would eliminate the "baggage" of having to sort
through the responses to long questions in the AnswerText column but
perhaps this isn't the case.

Bill E.
Hollywood, FL

Jun 27 '08 #1
2 4079
On Wed, 23 Apr 2008 07:17:30 -0700 (PDT), Bill E. wrote:

(snip)
>I would think that the optimizer would first use the index on
QuestionID and this would eliminate the "baggage" of having to sort
through the responses to long questions in the AnswerText column but
perhaps this isn't the case.
Hi Bill,

I'd think so too.

The only way to be sure is to test it. Preferably on the same hardware
and with the same data that your production system willl use.

Frankly though, I see no reason to choose the extra column. I do wonder
however if the column for the answer really has to be varchar(MAX). Are
you actually expecting ever to get answers over 8,000 characters in
length? You are aware that an average Word document has about 2,000
character per (full) page, are you?

--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
Jun 27 '08 #2
Hugo,

Thanks for your input.

Bill

Jun 27 '08 #3

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

Similar topics

2
by: Alexandre H. Guerra | last post by:
I needed to log all statements executed during a period of time and now i need ordering the long varchar column in the statements monitor table (STMT_TEXT) Is there any flag to set to release...
6
by: mike | last post by:
so I keep optimizing my fields down to the minimum character length necessary i.e., varchar(15), then I find out a month later its gotta get bigger, then a few months later, bigger again, etc. ...
5
by: Jay | last post by:
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...
5
by: emsik1001 | last post by:
I'm trying to upload XML into SQL Server 2000. I've never used openxml and I'm struggling with it. Below is the procedure with data. DECLARE @idoc int DECLARE @doc varchar (1000) SET @doc...
10
by: netzorro | last post by:
Hi all, considering the new varchar(max) type I have changed some text columns in some tables. The problem is the "SQL Native Client 2005.90.1399.00" odbc driver does not return any value for...
1
by: Stimp | last post by:
In terms of performance/system resources/good practice, is it generally better to perform paging within an SQL query rather than paging a datasource that implements that query? In this...
1
by: Omendra | last post by:
Hi, I am using SQL Server 2005 and i am using Stored Procedure something like :- I am getting error:- Msg 170, Level 15, State 1, Line 18: Incorrect syntax near 'MAX'. DECLARE @jid AS...
0
by: Omendra | last post by:
Hi,I am creating my SP as dynamic, On that i am defining varchar(max) to need to get more than 8000 characters. But my SP is taken only 8000 characters when i am doing Print to my SP. Please...
1
by: Omendra | last post by:
Hi, I had a VARCHAR(MAX) parameter declared in my stored procedure and trying to concatenat single column from a table which has 1500 rows into a string and keep in this variable, if i am not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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.