DATALENGTH
type or identity metadata
What changes
- Input
- argument expression or table identity metadata
- Output or change
- value
- Return type
- bigint if expression has an nvarchar(max), varbinary(max), or varchar(max) data type; otherwise int.
Syntax at a glance
DATALENGTH ( expression )
Work example
Check the storage byte count of a value or detect padding differences.
Compare values of different encodings with their declared type in mind.
Check your work DATALENGTH returns bytes, while LEN returns characters and omits trailing spaces.
Practice SQL
Open in SQL FlowSELECT LEN(N'Hi ') AS character_count, DATALENGTH(N'Hi ') AS byte_count;
Open Microsoft Learn for full syntax, permissions, and details for your version.