SELECT COUNT(*) FROM BigTable_1
如果我有超过 10 亿行,我应该使用哪种方式来获取表中的行数?
Which way I should to use to get number of rows in table if I have more than 1 billion of rows?
更新:例如,如果上面的查询出现超时问题",有什么方法可以优化它吗?如何更快地完成?
UPDATE: For example, if we have 'a timeout problem' with the query above is there any way to optimize it? How to do it quicker?
如果需要精确计数,必须使用COUNT (*)
If you need an exact count, you have to use COUNT (*)
如果您可以进行粗略计数,则可以使用分区中的行总和
If you are OK with a rough count, you can use a sum of rows in the partitions
SELECT SUM (Rows)
FROM sys.partitions
WHERE 1=1
And index_id IN (0, 1)
And OBJECT_ID = OBJECT_ID('Database.schema.Table');
如果你想用你的 COUNT 开玩笑,你可以执行以下操作
If you want to be funny with your COUNT, you can do the following
select COUNT (1/0) from BigTable_1
这篇关于大表中的行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
将每个子标记转换为具有多个分隔符的单列-SQLConverting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(将每个子标记转换为具有多个分隔符的单列-SQ
如何从多个表创建视图?How can I create a view from more than one table?(如何从多个表创建视图?)
根据前一行内的计算值创建计算值Create calculated value based on calculated value inside previous row(根据前一行内的计算值创建计算值)
如何将表格的前两列堆叠成一列,但也仅将第三How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何将表格的前两列堆
递归 t-sql 查询Recursive t-sql query(递归 t-sql 查询)
将月份名称转换为日期/月份编号(问题和答案的组Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(将月份名称转换为日期/月份编号(问题和答案的组合