Microsoft Dynamics CRM

{ADVANCED CRM KNOW-HOW} Know Table sizes within your CRM DATABASE

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

 

DBCC UPDATEUSAGE(0)

 

— DB size.

EXEC sp_spaceused

 

— Table row counts and sizes.

CREATE TABLE #t

(

    [name] NVARCHAR(128),

    [rows] CHAR(11),

    reserved VARCHAR(18),

    data VARCHAR(18),

    index_size VARCHAR(18),

    unused VARCHAR(18)

)

 

INSERT #t EXEC sp_msForEachTable ‘EXEC sp_spaceused ”?”’

 

SELECT *

FROM   #t

 

— # of rows.

SELECT SUM(CAST([rows] AS int)) AS [rows]

FROM   #t

 

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:

clip_image001

It gives a quick indication on the number of rows, reserved space and unused one.

Hope it helps!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s