Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7951525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:35:18+00:00 2026-06-04T02:35:18+00:00

I have come across with a doubt regarding stopping (killing) a query: There is

  • 0

I have come across with a doubt regarding stopping (killing) a query:

There is a procedure that changes the amount of data that a subscriber replicates (I don’t know all the details, it is some functionality that has been already implemented by the company), it’s in a transaction, so if it not finished it will rollback, while performing this procedure the replication for all subscribers is blocked, that is why we perform this operation during the night when the amount of subscribers replicating will be less or none. It is the weekend and I want to leave running the procedure (Friday 10pm) but I would like it to rollback if it doesn’t finish e.g. at 6am on Saturday and without the need to go to the office in order to stop the procedure manually.

setting it to run at 10pm is easy I have used

waitfor time '22:00'

I’m aware that in the same query can’t be a script that can stop the whole query since it is “sequential”, is there a way to do it opening other query tab? I hope that creating a job is not the only solution (if it is a solution at all).

Thank you for your replies.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:35:20+00:00Added an answer on June 4, 2026 at 2:35 am

    I suggest the easiest way to handle this is by putting your long-running process into a job. Doesn’t require an open instance of Management Studio with a reliably active network connection to the server from your workstation, and since a job can only be running one instance at a time, it will be much easier work identifying the actual process that is running the job (and deal with it accordingly).

    So let’s say I’ve convinced you, and you have a job called “Job I wanna kill” that is scheduled to run Friday night at 10 PM. The following stored procedure can be scheduled as a separate job, Saturday morning at 6:00 AM, or called manually.

    CREATE PROCEDURE dbo.Kill_Job_I_Wanna_Kill
    AS
    BEGIN
      SET NOCOUNT ON;
    
      DECLARE @id UNIQUEIDENTIFIER;
    
      -- since the job could be dropped and re-created:
      SELECT @id = job_id
        FROM msdb.dbo.sysjobs
        WHERE name = 'Job I wanna kill';
      -- note that it could also be renamed, so you'll have to
      -- decide how to properly identify this job in the long run
    
      DECLARE @t TABLE
      (
        ID VARBINARY(32), rd INT, rt INT, nrd INT, 
        nrt INT, nrs INT, rr INT, rs INT, rsID SYSNAME, 
        Running BIT, cs INT, cra INT, [state] INT
      );
    
      -- note that this XP is undocumented and unsupported!
      INSERT @t EXEC master.dbo.xp_sqlagent_enum_jobs 1, 'sa', @id;
    
      IF EXISTS (SELECT 1 FROM @t WHERE Running = 1)
      BEGIN
        PRINT 'Cancelling job!';
        EXEC msdb.dbo.sp_stop_job @job_id = @id;
      END
      ELSE
      BEGIN
        PRINT 'Job is not running!'
      END
    END
    GO
    

    When the job is killed successfully, the following will be seen as a printout when called manually or in the job step history when scheduled:

    Cancelling job!
    Job 'Job I wanna kill' stopped successfully.
    

    Now, there could be other complications – sometimes a rollback can take just as long as (or longer than) the time it took to get to that point. It all depends on what the long-running process is doing (I’m going to assume you’re rebuilding / reorganizing indexes).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have come across a class that has an immutable property: MyObject[] allObjs The
I have come across this rule in YSlow for performance improvement that says that
I have come across an odd behaviour in NSKeyedUnarchiver. I archive a data, for
I have come across articles that state that SELECT COUNT(*) FROM TABLE_NAME will be
I have come across Adobe MXML that looks very similar to Microsoft's XAML. Who
I have come across a situation that conflicts with my current understanding of methods
I have come across the fact that function pointers can be used to implement
I have come across a lot of optimization tips which say that you should
If have come across an anomaly where it seems that some machines that have
I have come across a very odd problem in C that I have never

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.