我正在使用非常大的表,如果执行查询我不能使用count获取行数需要很长时间。 [英] I'm working with very large tables if execute the query I cant get the number of rows using count it takes very long.

查看:180
本文介绍了我正在使用非常大的表,如果执行查询我不能使用count获取行数需要很长时间。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我想要一个sql查询的帮助,

目标:如果查询的结果超过1000行我想要抛出异常。也可以在C#

中执行此操作问题:如果执行查询,我正在使用非常大的表我无法使用计数获取行数需要很长时间。



请帮助我,



谢谢

解决方案





这些是这样做的方法:





http: //blogs.msdn.com/b/martijnh/archive/2010/07/15/sql-server-how-to-quickly-retrieve-accurate-row-count-for-table.aspx [<一个href =http://blogs.msdn.com/b/martijnh/archive/2010/07/15/sql-server-how-to-quickly-retrieve-accurate-row-count-for-table.aspxtarget =_ blanktitle =新窗口> ^ ]



快速参考使用此:

  SELECT  SUM(row_count)
FROM sys.dm_db_partiti on_stats
WHERE object_id = OBJECT_ID(' [表名]'
AND (index_id = 0 index_id = 1 );





享受:)


该表有超过1778969894行且正在增长

Hello,
I want help with a sql Query,
Goal: if the query s results is more then 1000 rows i want a exception thrown. Can aslo do this in C#
Problem: I'm working with very large tables if execute the query I cant get the number of rows using count it takes very long.

Please Help Me,

Thanks

解决方案

Hi,

Those are ways to do the same :


http://blogs.msdn.com/b/martijnh/archive/2010/07/15/sql-server-how-to-quickly-retrieve-accurate-row-count-for-table.aspx[^]

For quick ref Use this :

SELECT SUM (row_count)
FROM sys.dm_db_partition_stats
WHERE object_id=OBJECT_ID('[Table Name]')
AND (index_id=0 or index_id=1);



Enjoy :)


The table has over 1778969894 rows and is growing


这篇关于我正在使用非常大的表,如果执行查询我不能使用count获取行数需要很长时间。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆