SQL Server Management Studio - Finding all non empty tables

后端 未结 6 2100
隐瞒了意图╮
隐瞒了意图╮ 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:33

    This is a slight improvement to @jophab's answer. It will show schema for tables as well as compare rows = 0 using sys.partitions.

    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
    

提交回复
热议问题