SQL Server 2008: I have 1000 tables, I need to know which tables have data

后端 未结 5 2092
忘掉有多难
忘掉有多难 2020-12-30 01:25

Is there a way in SMSS to detect whether a table has any records? I need to get a list of tables that have records. perhaps there is a sql statement that will do the trick?<

5条回答
  •  旧巷少年郎
    2020-12-30 02:04

    A simpler syntax:

    SELECT  
        [Name] = o.name,
        [RowCount]= SUM(p.row_count)
    FROM SYS.DM_DB_PARTITION_STATS p
    INNER JOIN SYS.TABLES o ON p.[object_ID] = o.[object_id]
    WHERE index_id <= 1 -- Heap or clustered index only
    GROUP BY o.name
    ORDER BY 2 desc
    

提交回复
热议问题