Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Comments
Suvabrata Roy 10-Jul-14 4:01am    
what is the size of your DB and Table
ernest_hemingway077 10-Jul-14 4:05am    
size of the db of about 2tb and over 1mil rows in table

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 :
SQL
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 :)
 
Share this answer
 
v2
Comments
ernest_hemingway077 10-Jul-14 9:54am    
thanks for this
Suvabrata Roy 10-Jul-14 11:22am    
Welcome... :)
The table has over 1778969894 rows and is growing
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900