SQL Query to get table row size

In this example we will see how to get the table row size using SQL Query.

declare @tablename nvarchar(128) declare @colname nvarchar(128) declare @query nvarchar(max) set @tablename = 'YOUR TABLE NAME' set @colname = 'COLUMN NAME IN TABLE' set @query = 'select ' + @colname +' , (0' select @query = @query + ' + isnull(datalength(' + name + '), 1)' from sys.columns where object_id = object_id(@tablename) set @query = @query + ') as rowsize from ' + @tablename + ' order by rowsize desc' exec (@query)

Example: