Showing posts with label check all empty tables in a Database. Show all posts
Showing posts with label check all empty tables in a Database. Show all posts

Thursday, April 11, 2019

Microsoft SQL Server - How to check all empty tables in database?

Process to check all empty tables in a Database:

1. Select the database in the SSMS and open the "New Query" window.
2. Run the below query.

SELECT sch.name as SchemaName, t.NAME AS TableName,  p.rows AS RowCounts
FROM   sys.tables t
INNER JOIN  sys.partitions p ON t.object_id = p.OBJECT_ID
INNER JOIN sys.schemas sch on t.schema_id = sch.schema_id
WHERE  t.NAME NOT LIKE 'dt%'   AND t.is_ms_shipped = 0   AND p.rows <=0
GROUP BY  sch.name,t.Name, p.Rows
ORDER BY  sch.name,t.Name