How to find the largest sql objects in an SQL Server database

Sometimes you may need know how big some tables are, how many rows they have and how much disk space they use.

The following query looks for the biggest tables in size (MB) and number of rows:

    tbl.NAME AS TableName, as indexName,
    sum(p.rows) as RowCounts,
    (sum(a.total_pages) * 8) / 1024 as TotalSpaceMB, 
    (sum(a.used_pages) * 8) / 1024 as UsedSpaceMB, 
    (sum(a.data_pages) * 8) / 1024 as DataSpaceMB
    sys.tables tbl INNER JOIN 
    sys.indexes ind ON tbl.OBJECT_ID = ind.object_id INNER JOIN 
    sys.partitions p ON ind.object_id = p.OBJECT_ID AND ind.index_id = p.index_id INNER JOIN 
    sys.allocation_units a ON p.partition_id = a.container_id
    tbl.NAME NOT LIKE 'dt%' AND
    ind.OBJECT_ID > 255 AND   
    ind.index_id <= 1
GROUP BY     tbl.NAME, ind.object_id, ind.index_id, 
) as t1  ORDER BY TotalSpaceMB desc ,UsedSpaceMB desc