How do I count the number of rows a stored procedure would return the fastest way. Stored procedure returns rows around 100K to 1M records.
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.
Use SQL%ROWCOUNT if you are using Oracle. Mind that if you have multiple INSERT/UPDATE/DELETE , you'll need a variable to store the result from @@ROWCOUNT for each operation. Show activity on this post. @@RowCount will give you the number of records affected by a SQL Statement.
SQL Server @@ROWCOUNT with Try Catch@@ROWCOUNT returns the affected rows from any statement, even if it's not DML or a SELECT query.
Use the COUNT aggregate function to count the number of rows in a table. This function takes the name of the column as its argument (e.g., id ) and returns the number of rows for this particular column in the table (e.g., 5).
You can define output variable:
create procedure x
(@p1 int output)
as
select @p1 = count(*)
from Table
Select @@rowcount
:
SELECT @@ROWCOUNT;
After executing the stored procedure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With