Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 64797

Useful SQL Query (Part 2) – Count of records in each table from SQL

$
0
0

This is very useful query while doing upgrade, you can get the count of records in each table from source and target environment. This helps you with initial level of testing. I found it useful to share.

 DECLARE @QueryString NVARCHAR(MAX) ;  
 SELECT @QueryString = COALESCE(@QueryString + ' UNION ALL ','')  
            + 'SELECT '  
            + '''' + QUOTENAME(SCHEMA_NAME(sOBJ.schema_id))  
            + '.' + QUOTENAME(sOBJ.name) + '''' + ' AS [TableName]  
            , COUNT(*) AS [RowCount] FROM '  
            + QUOTENAME(SCHEMA_NAME(sOBJ.schema_id))  
            + '.' + QUOTENAME(sOBJ.name) + ' WITH (NOLOCK) '  
 FROM sys.objects AS sOBJ  
 WHERE  
    sOBJ.type = 'U'  
    AND sOBJ.is_ms_shipped = 0x0  
 ORDER BY SCHEMA_NAME(sOBJ.schema_id), sOBJ.name ;  
 EXEC sp_executesql @QueryString  


Viewing all articles
Browse latest Browse all 64797

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>