且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在SQL Server中使用TOP关键字计算结果集的总行数?

更新时间:2023-02-05 23:42:19

使用此查询可能会有所帮助u

use this query may be it helps u
select  top(3 or n) * ,(select count(*) from table_name) as COUNT from table_name



但请记住 TOP 关键字必须写首先,然后用逗号分隔其他列。

这里 COUNT (别名)将返回表格中的总行数



BY BKTHEBEST


but remember TOP keyword must write first and then other columns separated by comma.
here COUNT (alias name) will return total rows in your table

BY BKTHEBEST


您好,



也可以尝试这样...你可以找到使用系统表数据的表记录计数



Hi,

Try like this also... you can find the table record count using system table data

SELECT  TOP (3 or n) * , T.row_count
FROM table_name M
INNER JOIN (SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
FROM sys.dm_db_partition_stats st
WHERE index_id < 2
AND OBJECT_NAME(OBJECT_ID)='Table_Name') T ON T.TableName='Table_Name'





问候,

GVPrabu



Regards,
GVPrabu