Friday, June 6, 2014

Difference between Sql Server VARCHAR and VARCHAR(MAX) Data Type in SQL SERVER

Sql Server 2005 Varchar(MAX) data type was introduced as an alternate for Text data type. Varchar(Max) data type provides multiple advantages over Text data type.


Varchar(n)
nVarchar(max)
Basic definition
Non_Unicode variable Length character data type
Non-Unicode  large variable length character data type.
Storage capacity
It can store maximum 8000(bytes) Non-Unicode character .optional parameter n value from 1 byte to 8000 byte.
It can store maximum of 2 147 483 647 Non-Unicode characters (i.e. maximum storage capacity is: 2GB).
Index
We can create index on varchar column.
We cannot create Index on nvarchar(max) column.
How data is stored Physically?
It uses the normal data pages to store the data i.e. it stores the value ‘in a row’.
Sql server will try to store the value ‘in a row’ but if it could not then it will store the value ‘out of row’. i.e. It uses the normal data pages until the content actually fills 8k of data. When overflow happens, data is stored as old TEXT Data Type and a pointer is replacing the old content.
No. of Bytes required for each character
1 byte for each character.
1 byte for each character.
Which one use.
If you know that data to be stored in column is not more than 8000 character, then we can use this data type.
If we know that data will be cross more than 8 kb, then we can use this data type.

No comments:

Post a Comment