Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Currently running query inside a stored procedure

I have a stored procedure that is currently running, and seems to hang/lock on a specific query. How can i see which query? Preferably without modifying the proc.

Using

DBCC Inputbuffer (65)

gives me

Language Event 0 EXEC mySP;

like image 366
cederlof Avatar asked Feb 15 '12 12:02

cederlof


People also ask

How do you execute a query in a stored procedure?

Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure. In the Execute Procedure dialog box, specify a value for each parameter and whether it should pass a null value.

How do you show the currently running queries?

To list running queries, we need to use the 'show processlist' command. The following is the query. mysql> SHOW processlist; The following is the output of the above query.

Can we use SELECT statement in stored procedure?

We can not directly use stored procedures in a SELECT statement.


1 Answers

SELECT SUBSTRING(st.text, ( r.statement_start_offset / 2 ) + 1, 
              ( ( CASE WHEN r.statement_end_offset <= 0
                       THEN DATALENGTH(st.text) 
              ELSE r.statement_end_offset END - 
       r.statement_start_offset ) / 2 ) + 1) AS statement_text 
FROM   sys.dm_exec_requests r 
       CROSS APPLY sys.dm_exec_sql_text(sql_handle) st 
WHERE  session_id = 65 
like image 191
Martin Smith Avatar answered Sep 20 '22 16:09

Martin Smith