SQL Server Gems

Thursday, February 23, 2006

Using MAX in varchar, varbinary and nvarchar

In SQL Server 7.0, if you store a string to a varchar field, the maximum is 8000 bytes. If the demands of your application require you to store textual contents that is more than 8000 characters, you will have to either

(a) Split it into multiple rows.
(b) Use a binary field such as Text, NText

In SQL Server 2005, you can now make use of the MAX keyword to store up to 1-2 billion characters. Depending on what you kind of data you are storing, you can declare the field as Varchar(MAX), VarBinary(MAX) or NVarchar(MAX). Cool, right?!

Varchar(MAX) and VarBinary(Max) will allow you to store up to 2 billion characters and NVarchar(MAX) 1 billion chracters. However, use this with care, and only if you need to store a large number of characters or bytes.

0 Comments:

Post a Comment

<< Home