【问题标题】:Count tables in database have more than one record in SQL Server [closed]数据库中的计数表在 SQL Server 中有多个记录 [关闭]
【发布时间】:2018-02-12 14:43:17
【问题描述】:

是否有任何查询返回记录多于一行的表的计数?

【问题讨论】:

  • 是的,计数功能。
  • 从 INFORMATION_SCHEMA.TABLES 中选择计数 (*)
  • 这是一个返回我计数但我想计算非空表的查询

标签: sql tsql sql-server-2012


【解决方案1】:

一种方式:

select
    TableName = sc.name +'.'+ ta.name, RowCnt = sum(pa.rows) 
from 
    sys.tables ta
    join sys.partitions pa on pa.object_id = ta.object_id
    join sys.schemas sc on ta.schema_id = sc.schema_id
where 
    ta.is_ms_shipped = 0 
    AND pa.index_id IN (1,0)
group by sc.name,ta.name
having sum(pa.rows) > 0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-16
    • 2016-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 1970-01-01
    相关资源
    最近更新 更多