Sunday, September 14, 2008

Query a field size in Database (SQL Server)

If you want to query the size in bytes for a record or field in database (SQL Server), you can use the DATALENGTH function.
The DATALENGTH function can return the length in bytes for any data types including text, ntext, image and varbinary.

For example you want to know the size of Field1 in TableA just run the following query:

SELECT Field1, DATALENGTH(Field1) AS [Size Field1 in bytes] FROM TableA

The output will be the value of Field1 and it's size in bytes for each rows record in TableA

0 comments: