I have the following query in SQL Server:
select * from sales
This returns about a billion rows, and I need to process the data. I would like to show the progress while the data is being processed using something like the following:
res=conn.execute('select * from sales s1')
total_rows = ?
processed_rows = 0
step_size = 10000
while True:
data = res.fetchmany(step_size)
processed_rows += step_size
print "Progress: %s / %s" % (processed_rows, total_rows)
Is there a way to get the total number of rows in a SQL query without running another query (or doing an operation such as len(res.fetchall())
, which will add a lot of overhead to the above)?
Note: I'm not interested in paginating here (which is what should be done). This is more a question to see if it's possible to get the TOTAL ROW COUNT in a query in SQL Server BEFORE paginating/processing the data.