SQL Server Variable – How to Increase Variable Size

database-administrationsqlsql server

It is not clear to me how a varchar(max) is declared or used in an SQL Server e.g. 2005
Is a variable declared as varchar(300000) for example considered as a varchar(max)?
E.g. I am seeing in a DB in a table a variable is declared as varchar(8000).
Can I simply increase it to varchar(300000)?
Thanks

Best Answer

When you define a maximum size explicitly, then you cannot define higher than CHAR(8000) / VARCHAR(8000) or NCHAR(4000) / NVARCHAR(4000).

When you define a variable as CHAR(max) or VARCHAR(max), you set the maximum size of that variable to 2GB.

There is no way to define a variable with a maximum size between 8000 bytes and 2GB.