Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get the rowcount before executing a stored procedure?

I have some complex stored procedures that may return many thousands of rows, and take a long time to complete.

Is there any way to find out how many rows are going to be returned before the query executes and fetches the data?

This is with Visual Studio 2005, a Winforms application and SQL Server 2005.

like image 793
Piku Avatar asked Oct 31 '08 15:10

Piku


People also ask

How do I return the number of rows affected by a stored procedure?

The executeUpdate method will return an int value that contains the number of rows affected by the stored procedure, but the execute method doesn't. If you use the execute method and want to get the count of the number of rows affected, you can call the getUpdateCount method after you run the stored procedure.

How do you get Rowcount?

Counting all of the Rows in a Table. To counts all of the rows in a table, whether they contain NULL values or not, use COUNT(*). That form of the COUNT() function basically returns the number of rows in a result set returned by a SELECT statement.

How do you return the total records count returned by a stored procedure?

The Table fields along with the Row Number (Row Index) field are selected using Common Table Expression (CTE) and then the results are filtered based on the PageIndex and PageSize parameters. RecordCount is an OUTPUT parameter which is used for returning the Total Record Count (Total Rows) of the Table.


1 Answers

You mentioned your stored procedures take a long time to complete. Is the majority of the time taken up during the process of selecting the rows from the database or returning the rows to the caller?

If it is the latter, maybe you can create a mirror version of your SP that just gets the count instead of the actual rows. If it is the former, well, there isn't really that much you can do since it is the act of finding the eligible rows which is slow.

like image 51
Maxam Avatar answered Sep 24 '22 14:09

Maxam