Recently in my project, as part of maintenance and data clean up activity, we needed to know the relative sizes occupied by various tables in CRM database. This was to prioritize clean-up based on table sizes.
Since this was CRM on premise we could quickly fire a query to check this:
SET NOCOUNT ON
— DB size.
— Table row counts and sizes.
CREATE TABLE #t
INSERT #t EXEC sp_msForEachTable ‘EXEC sp_spaceused ”?”’
— # of rows.
SELECT SUM(CAST([rows] AS int)) AS [rows]
DROP TABLE #t
This query uses a stored procedure provided by Microsoft to check space and runs it through all the tables in database.
The output is similar to below which can be saved to csv and then filtered to see which tables are using the most space:
It gives a quick indication on the number of rows, reserved space and unused one.
Hope it helps!