How do I troubleshoot a stored procedure in SQL Server?

How do I troubleshoot a stored procedure in SQL Server?

Debugging options

  1. Start Debugging. To start debugging a SQL server stored procedure in SQL Server, press ALT + F5, or go to Debug -> Start Debugging, as shown in the figure below:
  2. Stepping Through Script.
  3. Run To Cursor.
  4. The Local Window.
  5. The Watch Window.
  6. The Call Stack.
  7. The Immediate Window.
  8. Breakpoints.

How do you turn off parameter sniffing?

Parameter sniffing is enabled by default in SQL Server, you can disable it by turning on the Trace Flag 4136 at the instance level, which will affects all databases hosted in the same instance that may not be acceptable for instance with many databases serving different workload types.

Can I debug a Stored Procedure?

The Transact-SQL debugger allows you to interactively debug stored procedures by displaying the SQL call stack, local variables, and parameters for the SQL stored procedure.

When does a stored procedure become very slow?

We are struggling with a strange problem: a stored procedure become extremely slow when raw SQL is executed fairly fast. SQL Server 2008 R2 Express Edition SP1 10.50.2500.0 with several databases on it.

Which is the fastest SQL Server stored procedure?

SQL Server 2008 R2 Express Edition SP1 10.50.2500.0 with several databases on it. a stored procedure which takes different parameters and does select among multiple tables from the database. The stored procedure was working pretty good and fast (it’s execution usually took 1-2 seconds).

How long does it take to re-create a stored procedure?

Today, it takes about 18 seconds. I ran into the problem yesterday as well, and it seemed to be solved by DROPing and re-CREATEing the stored procedure. Today, that trick doesn’t appear to be working.

How long does it take to execute a stored SQL query?

This stored procedure, after massive data update on the database (a lot tables and rows were affected by the update, however DB size was almost unchanged, now it is 752 ) become to work extremely slow. Now it takes from 20 to 90 seconds. If I take raw SQL query from the stored procedure – it is executed within 1-2 seconds.