tag:blogger.com,1999:blog-5833268165048553764.post2758146446712213187..comments2022-12-05T00:24:18.133-08:00Comments on Inkey's ability pond: Find all empty tables in SQL Server Databasevinay pugaliahttp://www.blogger.com/profile/07027426501611091260noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-5833268165048553764.post-87754014769601983012012-04-09T15:57:51.056-07:002012-04-09T15:57:51.056-07:00;WITH TableRows AS
(
SELECT
SUM(row_coun...;WITH TableRows AS<br />(<br /> SELECT <br /> SUM(row_count) AS [RowCount], <br /> OBJECT_NAME(OBJECT_ID) AS TableName<br /> FROM <br /> sys.dm_db_partition_stats<br /> WHERE <br /> index_id = 0 OR index_id = 1<br /> GROUP BY <br /> OBJECT_ID<br />)<br />SELECT *<br />FROM TableRows<br />WHERE [RowCount] = 0<br /><br />The inner select in the CTE (Common Table Expression) calculates the number of rows for each table and groups them by table (OBJECT_ID), and the outer SELECT from the CTE then grabs only those rows (tables) which have a total number of rows equal to zero.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-5833268165048553764.post-23175034587139779502012-04-09T15:54:06.368-07:002012-04-09T15:54:06.368-07:00It works. Thanks.It works. Thanks.Anonymousnoreply@blogger.com