Click here to Skip to main content
16,013,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,
I have one stored procedure in that i have one column (Area varchar(50)). If a user use only 10 characters and how to free the other memory by using sql
Posted

1 solution

You don't really have to. :)

SQL Server does not really allocate space based on the datatype definition in your table. It allocates enough space to hold the data (so if you have 10 chars, it only allocates space for 10 chars).

If you use SQL Server 2005 or above, you can use the varchar(max) datatype, which will hold data up to 2GB, and you never really have to worry about the size. SQL Server will do the right thing for you. Only when your data gets bigger than 8K, you might get a small perf hit when using varchar(max) as it won't fit on a single page anymore, but if you have a lot of data that is smaller than 8K, you might as well use varchar(max) as internally in the engine varchar(N) and varchar(max) are treated very simular as long as the data is less than 8K.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900