Monday, March 12, 2012

How to cancel a processing request?

Hello ,

I've execute a wrong sql request from an ETL. This request is inserting lots of rows in a table. I want to cancel that process, is it possible to do this? If yes, how can I cancel that request?

Thanks,

Stop or 'kill' the client application that is doing the inserts.|||

Find out the SPID that the request is running on, and then run KILL <thespidnumber>

You can probably find the SPID by running the query below, or by using sp_who2

SETNOCOUNTON;

DECLARE @.SpID smallint

DECLARE spID_Cursor CURSOR

FORWARD_ONLYREAD_ONLYFOR

SELECTTOP 25 spid

FROM master..sysprocesses

WHEREstatus='runnable'

AND spid > 50 -- Eliminate system SPIDs

AND spid <> 102 -- Replace with your SPID

ORDERBY CPU DESC

OPEN spID_Cursor

FETCHNEXTFROM spID_Cursor

INTO @.spID

WHILE@.@.FETCH_STATUS= 0

BEGIN

PRINT'Spid #: '+STR(@.spID)

EXEC('DBCC INPUTBUFFER ('+ @.spID +')')

FETCHNEXTFROM spID_Cursor

INTO @.spID

END

-- Close and deallocate the cursor

CLOSE spID_Cursor

DEALLOCATE spID_Cursor

|||thx more than I expected

No comments:

Post a Comment