Actually,I need to catch each query (update/delete) and rows affected by it of a stored procedure in order to keep track. You can assume that that stored procedure contains only delete and update commands.
I have created following function
CREATE Function [dbo].[CURRENT_Query] (@SPID int)
Returns nvarchar(max)
Begin
Declare @CURRENT_Query nvarchar(max)
SET @CURRENT_Query =(SELECT t.text
FROM sys.dm_exec_requests AS r
CROSS APPLY sys.dm_exec_sql_text(r.sql_handle) AS t
WHERE session_id = @SPID )
Return @CURRENT_Query
End
and then fired following queries
declare @row_count int
Update t set T_id =20
from table_name t
where t_id in ('10','11','12')
set @row_count =(select @@rowcount)
select dbo.CURRENT_Query(@@spid),@row_count
now I want to catch query and count of rows affected by it. I have also tried using after update trigger on that table using
EXEC sp_executesql N'DBCC INPUTBUFFER(@@spid) WITH NO_INFOMSGS'
but I was unable to catch row count affected by queries.
I tried using following query also
DECLARE @sqltext VARBINARY(128)
SELECT @sqltext = sql_handle
FROM sys.sysprocesses
WHERE spid = 104
SELECT TEXT
FROM sys.dm_exec_sql_text(@sqltext)
Please suggest optimised solution so that I can track each query and row count on a table in a stored procedure