--第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