Monday 28 August 2017

Get the list of all empty tables in SQL Server

With the help of below script we will get the list of all tables which are empty (No record in table).
;WITH EmptyRowstbl AS
(
   SELECT SUM(row_count) AS [TotalRows],
          OBJECT_NAME(OBJECT_ID) AS TableName
                                     FROM sys.dm_db_partition_stats
   WHERE index_id = 0 OR index_id = 1
   GROUP BY OBJECT_ID
)
SELECT * FROM EmptyRowstbl
WHERE [TotalRows] = 0
  
See some table



No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts