Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server can't store more then 4000 characters in a local string variable

I tried to use text or ntext as the variable's type but they are disallowed.
Is there a way to bypass this?

like image 889
the_drow Avatar asked Mar 02 '10 08:03

the_drow


People also ask

How do I store more than 4000 characters in SQL Server?

The storage size, in bytes, is two times the actual length of data entered + 2 bytes. The ISO synonyms for nvarchar are national char varying and national character varying. So if you specify nvarchar(max) you can store up to 1 billion 2-byte Unicode characters.

Is nvarchar 4000 the same as nvarchar Max?

The answers is: there is no different between nvarchar(7) and nvarchar(4000) in term of performance & storage size. There is an interesting thing is that: if you change nvarchar(7) or nvarchar(4000) to nvarchar(max). There is a difference in term of performance & storage size. Wow, Why is this happen?

What is the limit of varchar Max in SQL Server?

varchar [ ( n | max ) ] Use n to define the string size in bytes and can be a value from 1 through 8,000, or use max to indicate a column constraint size up to a maximum storage of 2^31-1 bytes (2 GB).


1 Answers

For anything not MSSQL 2005 or MSSQL 2008:


You can get 8000 in a varchar(8000)

Another option is to use a temporary table and populate that with the information you need. Use an autoindex to maintain order.

like image 188
cjk Avatar answered Sep 30 '22 12:09

cjk