Thursday, June 18, 2015

SQL - Important Facts of VARCHAR Data Type

Important Facts of VARCHAR Data Type

Varchar is used to store variable length alphanumeric (non-Unicode character) data which supports space efficiency and store data without wasting the extra space. Due to non-Unicode conduct, it takes 1 Byte per character. The storage size is the actual length of the data entered + 2 bytes. A varchar column defines the string length and can be a value from 1 through 8,000. Varchar indicates that the maximum storage size is 2^31-1 bytes (2 GB).

A VARCHAR has an automatic internal limit and by defaults limit of varchar is 30 characters if you are not specify the length.  If you are converting to varchar without specifying the length results to having maximum of 30 characters due to default limit nature of varchar data type.

A varchar must mean you can store any string of any length in it and you can set it as VARCHAR (MAX).

Note: If you really do want a 1 character field in a table, specify CHAR (1) not VARCHAR (1) because of the overhead. A zero length field actually takes 3 more bytes to store than the fixed length field.

No comments:

Post a Comment

Popular Posts