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

后端 未结 5 2088
忘掉有多难
忘掉有多难 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 01:57

    Hope, It helps you-

    SELECT name AS [TableList] FROM SYS.DM_DB_PARTITION_STATS s 
    INNER JOIN sys.tables t ON t.[object_id] = s.[object_id]
    WHERE row_count = 0
    

    This code shows that list of tables, which does not contain any data or row.

    Thanks!!!

提交回复
热议问题