[英]Sql query to get total records for specific table available in multiple databases on same server
I have one requirement where I need to find the total number of records in specific table "ENTITY", available in all the databases that we have on our SQL Server. 我有一个要求,我需要在特定表“ ENTITY”中找到记录总数,该表在SQL Server上所有数据库中都可用。 I want to write a single query to get records from multiple databases for this table. 我想编写一个查询来从该表的多个数据库中获取记录。 Can someone please help me in this regard? 有人可以在这方面帮助我吗?
Thanks. 谢谢。
Option One 选项一
SELECT SUM(P.[Rows]) AS [Count]
FROM SYS.objects O
JOIN SYS.partitions P
ON P.[object_id] = O.[object_id]
AND P.index_id < 2
WHERE O.name = 'Table'
Option Two 选项二
SELECT COUNT(1)
FROM dbo.Table
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.