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

相关文章:

  • 2021-11-13
  • 2021-06-19
  • 2021-05-21
  • 2021-12-29
  • 2022-12-23
  • 2022-02-20
  • 2022-12-23
猜你喜欢
  • 2021-11-21
  • 2021-07-29
  • 2021-12-29
相关资源
相似解决方案