SqlServer快速获得表总记录数(大数据量)

--第1种 执行全表扫描才能获得行数

SELECT count(*) FROM BUS_tb_UserGradePrice

--第2种 执行扫描全表id不为空的,获得行数

select count(userid) from BUS_tb_UserGradePrice where userid is not NULL

--第3种 直接从系统表中查询表的总记录数(特别适合大数据)

SELECT rows FROM sysindexes WHERE id = OBJECT_ID('dbo.BUS_tb_UserGradePrice') AND indid < 2

**其中“dbo.BUS_tb_UserGradePrice”为需要查找的表名

--第4种 存储过程获取总记录数
ALTER PROCEDURE [dbo].[sp_RowCount]  
    @table NVARCHAR(100)  
    AS  
BEGIN  
    SET NOCOUNT ON;  
    DECLARE @tb TABLE(name SYSNAME,[RowCount] NVARCHAR(4000),c NVARCHAR(4000),d NVARCHAR(4000),e NVARCHAR(4000),f NVARCHAR(4000))  
    INSERT INTO @tb EXEC sp_spaceused @table  
    SELECT TOP 1 [RowCount] FROM @tb    
END  --------------------- 本文来自 hanihehe 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/hanihehe/article/details/52638655?utm_source=copy 

原文地址:https://www.cnblogs.com/lenmom/p/9703727.html