Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 varchar(max) clarification - minimum data

Author  Topic 

dean.c4
Starting Member

14 Posts

Posted - 2011-06-09 : 15:19:29
If I'm building an insert stored proc and define one of the params as varchar(max), and nothing gets stuck into this parameter, how much space is wasted or reserved on a basically empty field?

In a stored proc, can you define it as varchar() and get the same results or must it say (max) if you truly don't know the length of whats going in there?

Thanks.

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2011-06-09 : 15:47:10
I size it to the largest value I intend to allow. If you really don't know, and expect it to be large, use max.

Varchar doesn't take any space in row if it is empty.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-06-09 : 15:47:20
It's stores as much as you pass, 0 characters stores 0 bytes of data. You must specify (max) if you intend to store that much. ALWAYS specify a length or max for varchar/nvarchar/varbinary data types.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-06-14 : 04:46:13
<<
ALWAYS specify a length or max for varchar/nvarchar/varbinary data types.
>>

Here is what happens when you dont specify
http://beyondrelational.com/blogs/madhivanan/archive/2007/12/04/column-length-and-data-length.aspx


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -