List Empty Tables in SQL Server
Sometime we create tables in the DB but never use. If we need to
find the list of all that tables in complete DB it will be an issue for a
developer to check each table
here’s a simple query to list all empty tables in your SQL Server database that uses a Dynamic Management View called dm_db_partition_stats which returns empty table current database.
;WITH EmptyRows AS
here’s a simple query to list all empty tables in your SQL Server database that uses a Dynamic Management View called dm_db_partition_stats which returns empty table current database.
;WITH EmptyRows 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
EmptyRows
WHERE [TotalRows] = 0