Cry How to...

Obtain record field size information


To see the minimum, average and maximum storage requirements of a field in a given table:

Select min(datalength(<field>)),
    avg(datalength(<field>)),
    max(datalength(<field>)) from <table>;

where:

 <field> is the name of the field of interest

 <table> the name of the table.

Be aware that the total storage requirements for a record are more than the sum of the size of the individual fields. For example datalength on a varchar field will return the number of characters and will not include the overhead for storing that number.


These notes have been tested against SQL Server 7 and SQL Server 2000.



About the author: is a dedicated software developer and webmaster. For his day job he develops websites and desktop applications as well as providing IT services. He moonlights as a technical author and consultant.