SQL: Script para recuprar tamanho das tabelas

oraculum

Tagged: ,


Pequeno script para recuperar o tamanho, quantidade de linhas e espaços alocados inutilmente pela banco na tabela (unused)

1
2
3
4
5
6
7
8
9
10
11
12
SELECT  object_name(id) AS name,
        indid, 
        rowcnt AS ROWS, 
        reserved * 8 AS reserved_kb, 
        dpages * 8 AS data_kb, 
        (SUM(used) * 8) - (dpages * 8) AS index_size_kb, 
        (SUM(reserved) * 8) - (SUM(used) * 8) AS unused_kb 
FROM sysindexes 
WHERE indid IN (0,1) -- cluster e não cluster 
AND   OBJECTPROPERTY(id, 'IsUserTable') = 1 
GROUP BY id, indid, rowcnt, reserved, dpages 
ORDER BY rowcnt DESC
Share Button

Leave a Reply