all groups > sql server programming > may 2004 >
You're in the

sql server programming

group:

varchar vs. text in stored procs


varchar vs. text in stored procs Anubis
5/24/2004 9:58:55 PM
sql server programming:
Hi All,


Just a quick one which I have not been able to find a straight answer for
yet...

When programming a stored proc, you can declare a list of parameters in the
top. Currently I am using varchar 8000 to collect a long string of
information which is then broken into an array from entered information on
the web page which calls the process. However as you can imagine, this
limits my input capabilities.

If I was to change the variable from varchar 8000 to text would this make a
difference in call time? I know when data is stored in a database in text
or ntext it's stored in a file off the database, is this the same for
declared parameters?

Are there any 'down sides' to using text instead of varchar 8000 for this
type of application?

Any help would be appreciated!

- Steve



Re: varchar vs. text in stored procs Wayne Snyder
5/25/2004 6:30:16 AM
Text fields ARE stored in the database, but in a different structure... They
have been (traditionally ) slower to access and update ( so do some
testing)...

The downside to using text/image data types in a stored procedure is that
you can NOT create a variable of these data types, therefore you can not
pass a parameter of these data types... You would have to create a row in
the database with a key and the text value and pass the key to the row to
the SP. Then the SP would have to look up the row and do the work, then
delete the row ( I suppose).



--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)

I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org


[quoted text, click to view]

Re: varchar vs. text in stored procs Louis Davidson
5/25/2004 10:16:02 AM
But the upside is that you can store up to 2GB in a single row :)


Also, you can pass parameters of type text, you just cannot do any
manipulation with the parameter:

create table testText
(
testTextId int primary key,
textCol text
)
go
create procedure testTextInsert
(
@testTextId int,
@textCol text
) as
set nocount on
begin
insert into testText (testTextId, textCol)
values (@testTextId, @textCol)
end
go


exec testTextInsert 1, 'text'
go

It would be way to ugly to demonstrate that you can insert > 8000 chars, but
it does work (I tested it with 10000.)

--
----------------------------------------------------------------------------
Louis Davidson (drsql@hotmail.com)
Compass Technology Management

Pro SQL Server 2000 Database Design
http://www.apress.com/book/bookDisplay.html?bID=266

Note: Please reply to the newsgroups only unless you are
interested in consulting services. All other replies will be ignored :)

[quoted text, click to view]

Re: varchar vs. text in stored procs Ryan
5/25/2004 11:16:02 PM
Steve -

[quoted text, click to view]

Text, ntext and image values are stored on the Text/Image pages separately
from the other data, stored on the Data pages.
SQL Server 2000 now supports a "text in row" table option that specifies
that small text, ntext, and image values be placed in the Data pages with
other data values in the same data row instead of Text/Image pages. This
increases the speed of read and write operations and reduces the amount of
space used to store small text, ntext, and image data values.
You can set a text in row table option with sp_tableoption stored procedure
[quoted text, click to view]

MSDN on "text in row" and performance -

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_ta-tz_1cfi.asp

Text performance tips for SQL Server 2000 -

http://www.sql-server-performance.com/database_design.asp
http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=309

Hope this helps answer some of your questions.

--
Regards,

Ryan
[quoted text, click to view]

Re: varchar vs. text in stored procs Anubis
5/26/2004 9:34:18 PM
Hello All,

Thank you for your assistance. It's certainly given me some food for
thought.

:-)

-Steve





[quoted text, click to view]

AddThis Social Bookmark Button