Tip #1409: Count records for all tables in Dataverse

Want to count all records in all Dataverse tables like a boss? Say no mo.

SELECT 
 CONCAT(
 'SELECT ''', name, ''' AS TableName, 
 COUNT_BIG(1) AS CountOfRows FROM ', 
 name,
 ' UNION')
FROM 
	sys.tables
WHERE
	TYPE = 'U'
AND SCHEMA_ID = 1
  • Copy all results (Ctrl-A), open New Query window (Ctrl-N), paste (Ctrl-V)
  • Scroll to the end, remove the last word UNION and add ORDER BY 2 DESC line
  • Execute
  • You are welcome
Screenshot of T-SQL table results with the partial list of table names and row count for each displayed.

Note: the execution may timeout if your Dataverse is of any decent size. Use trial/error approach to figure out executable chunks – you probably know your largest tables anyway.

6 thoughts on “Tip #1409: Count records for all tables in Dataverse

  1. Scott says:

    You could use the Fast Record Counter in XRMToolbox by Ivan Ficko to get the same, yes?
    https://www.xrmtoolbox.com/plugins/Fic.XTB.FastRecordCounter/

  2. I have created a browser-based tool to count total records for given table. https://AshishVishwakarma.com/DataverseRowsCounter/ Please have a look.

  3. John O says:

    Does anyone have a similar script to do the same report for the number of columns?

  4. Anupam says:

    In the SQL approach make sure, it support only 200 literal at once.

    you have to split your query if it has more than 200 unions.

Leave a Reply

Your email address will not be published. Required fields are marked *