Home » SQL SERVER VARCHAR

SQL SERVER VARCHAR

SQL Server VARCHAR Data Type is used to store non-unicode string data of varaible length.




  • VARCHAR data type is used to store non-Unicode string data of variable length.
  • Stores data at 1 byte per character.
  • Supports up to 8000 characters.
Syntax
varchar(n)
or
varchar(max)

n specify the string length that ranges from 1 to 8000. Default value fo n is 1.

max specify the maximum storage size which is 231-1 bytes (2 GB).

DataStorage Vs Length

Here we have a variable @strtxt of datatype varchar of size 30.

As varchar takes 1bytes per character to store the data so it takes 9 bytes to store @strtxt value ‘microsoft’ that is lenght of @strtxt * 1 bytes (9 *1) =9.

It is variable -length so, it takes actual length size of string that is 9 for ‘‘microsoft’.

DECLARE @Str VARCHAR(30)

SET @Str = 'Microsoft'

SELECT @Str AS Strtext, DATALENGTH(@Str) AS StrText_OccupiedLength ,
LEN(@Str) AS StrText_length

Varchar can not store unicode data

Varchar can not store unicode data , here we try to store hindi language text to @str variable of type varchar.

DECLARE @Str VARCHAR(30)

SET @Str = N'माइक्रोसॉफ्ट'

SELECT @Str AS Strtext, DATALENGTH(@Str) AS StrText_OccupiedLength ,
LEN(@Str) AS StrText_length

 

As you can see, it does not support unicode characters or multilingual data.

Recomended for you

How to get the detailed information of all datatypes in SQL Server ?

SQL Server VARCHAR vs NVARCAR

SQL Server CHAR vs NCHAR

 




Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.