I have 10 stored procedures as follows: SP1,SP2,.....,SP10 These stored procedures do some stuff. I need to run these procedures as follows: EXECUTE SP1; EXECUTE SP2; ... EXECUTE SP10;
When SQL server finshes to complete execution of these procedures, it gives ten lines showing any row changes caused by all these stored procedures. What i want to do is that after Execution of all stored procedures SQL Server also gives in output window the execution time for each Stored Procedures. Can i do this? I am sure that for achieving this task i need to modify stored procedures but i don't have any idea how to do it... Please help me. Thanks.
You need the actual execution plan. You can see these from running the SQL query in SQL Management studio with the right button pressed (they'll appear as a tab in the results window). This will show you what parts of the sproc is being run and the time taken up by each bit - just what you want to tune.
The type_desc column includes the object type while the execution_count column shows the number of times the stored procedure has been executed since it was last compiled. This can be useful information when researching performance issues.
Using Client StatisticsGo to Menu >> Query >> Select Include client Statistics. Execute your query. In the results panel, you can see a new tab Client Statistics. Go to the Client Statistics tab to see the execution time.
Assuming management studio or some other environment with an output pane you can;
SET STATISTICS TIME ON
EXEC SP1
EXEC SP2
...
SET STATISTICS TIME OFF
You can use Sql Server Profiler for this purposes it provides a lot of useful info along the each executed query and Stored procedure as well.
MSDN: SQL Profiler Data Columns
SQL Profiler displays the execution time for each event
An other straightforward way:
declare @start datetime = getdate()
-- your SQL statements
exec dbo.MyStoredProcedure
declare @executionTimeInMilliseconds int = datediff(ms, @start, getdate())
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