According to MSDN the storage size of a VARCHAR data type is the actual length of the data entered + 2 bytes. I'm trying to understand why when I run this query:
DECLARE @VARCHAR VARCHAR(40) = 'RACING CLUB DE AVELLANEDA'
SELECT DATALENGTH(@VARCHAR) AS Bytes, LEN(@VARCHAR) AS Characters;
The storage size of @VARCHAR is the same as it was a CHAR data type, It's 25 and not 27 (25+2).
Does it has something to do with DATALENGTH function?
datalength will tell you the number of bytes of data, which doesn't include the 2 bytes that precede that data in storage. The 2 byte overhead of a varchar is for recording the number of bytes in the string - i.e. in your case 25
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With