One of my DBs have grown closer to permitted size.
Inorder to find out the table containing the max data, i used the following query:
exec sp_MSforeachtable @command1="print '?' exec sp_spaceused '?'"
It returned the culprit table comprising the max data.
As a next step, i want to cleanup the rows based on the size. For this, i would like to order the rows based on size.
How to achieve this using a query? Are there any tools to do this?
Below is a SQL query to find row size. The query uses DATALENGTH function, which returns the number of bytes used to represent a column data. A row may consist of fixed, variable data types. A varchar is a variable datatype which means that a varchar(50) column may contain a value with only 20 characters.
Go to Table > Total Row. The Total Row is inserted at the bottom of your table. Note: If you apply formulas to a total row, then toggle the total row off and on, Excel will remember your formulas.
SELECT table_name "Table Name", table_rows "Rows Count", round(((data_length + index_length)/1024/1024),2) "Table Size (MB)" FROM information_schema. TABLES WHERE table_schema = "mydb"; The above SQL statement calculates size of all tables in a database in mysql server.
This will give you a list of rows by size, just set @table and @idcol accordingly (as written it'll run against the Northwind sample)
declare @table varchar(20)
declare @idcol varchar(10)
declare @sql varchar(1000)
set @table = 'Employees'
set @idcol = 'EmployeeId'
set @sql = 'select ' + @idcol +' , (0'
select @sql = @sql + ' + isnull(datalength(' + name + '), 1)'
from syscolumns where id = object_id(@table)
set @sql = @sql + ') as rowsize from ' + @table + ' order by rowsize desc'
exec (@sql)
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