DATALENGTH VARCHAR in SQL Server -


according msdn storage size of varchar data type actual length of data entered + 2 bytes. i'm trying understand why when run query:

declare @varchar varchar(40) = 'racing club de avellaneda' select datalength(@varchar) bytes, len(@varchar) characters; 

the storage size of @varchar same char data type, it's 25 , not 27 (25+2).

does has datalength function?

datalength tell number of bytes of data, doesn't include 2 bytes precede data in storage. 2 byte overhead of varchar recording number of bytes in string - i.e. in case 25


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -