"If at first you don't succeed; call it version 1.0" :-Unknown

Pages

Wednesday, April 22, 2015

Total number of records of all tables in a MSSQL database

Total number of records of all tables in a MSSQL database


Run the below query agganist the database you want the result


SELECT      QUOTENAME(SCHEMA_NAME(sOBJ.schema_id)),QUOTENAME(sOBJ.name) AS [TableName]      , SUM(sdmvPTNS.row_count) AS [RowCount]FROM      sys.objects AS sOBJ      INNER JOIN sys.dm_db_partition_stats AS sdmvPTNS            ON sOBJ.object_id = sdmvPTNS.object_id
WHERE      sOBJ.type = 'U'
      AND sOBJ.is_ms_shipped = 0x0      AND sdmvPTNS.index_id < 2GROUP BY
      sOBJ.schema_id
      , sOBJ.name      having SUM(sdmvPTNS.row_count)>0ORDER BY [TableName]
GO




If u had any trouble just ask, Happy to help u :)
Stay Tune...
Have a nice day... 'N happy Coding :)

No comments: