"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Tuesday, May 3, 2011

Choosing between char, varchar, varchar(MAX) and text datatype in SQL Server 2005

char, varchar, varchar(MAX) and text datatype are used for storing character string. Note you cannot store multilingual data. i.e. You will not allowed to store japanes or hindi characters.

Char datatype
  1.  Stores character (non-unicode) data.
  2.  Stores data in fixed-length format.  
  3.  Choose char datatype when size of data is consistent.
Varchar datatype

  1. Stores Character (non-unicode) data.
  2. Stores data in variable-length format.
  3. Choose varchar datatype when size of data varies between 8000 bytes

Varchar(MAX) datatype
  1. Stores Character (non-unicode) data.
  2. Stores data in variable-length format.
  3. Choose varchar datatype when size of data varies and it may exceeds 8000 bytes.

Text datatype

  1. Text datatype is used in previous versions of SQL Server, it is recommended to use Varchar(MAX) instead of Text datatype, as ntext, text, and image data types will be removed in a future version of Microsoft SQL Server
  2. Stores large amount of character string
  3. Stores data in variable-length format.
  4. Choose text datatype when size of data varies may exceeds 8000 bytes.



Have a nice day... 'N happy Coding :)

No comments: