SQL Server Management Studio - Finding all non empty tables

后端 未结 6 2103
隐瞒了意图╮
隐瞒了意图╮ 2020-12-16 02:00

Is there a way for SQL Server Management Studio Express How to list all the non empty tables? I have over 100 tables to go through and check for data.

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 02:11

    Try :

    WITH TableRows AS
    (
       SELECT 
          SUM(row_count) AS [RowCount], 
          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 TableRows
    WHERE [RowCount] > 0
    

提交回复
热议问题