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 6668171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:00:42+00:00 2026-05-26T03:00:42+00:00

I have a set of maintenance tasks in several databases that are triggered by

  • 0

I have a set of maintenance tasks in several databases that are triggered by a master stored procedure. The master stored procedure is started using sp_procoption to start on mssql startup. Then at a specified day and time, runs the child procedures in all of my databases.

I need to update this master script.

To clean up the update procedure, and not require stopping and restarting sql (to ensure that only one instance of the master procedure is running), I would like to be able to stop the stored procedure then restart it at the end of the update script. Restarting is not an issue, but does anyone know a way to stop the procedure from the update script?

Here is the script for my master scheduling proc:

USE master
GO
IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'weekly_maintenance_task')
    DROP PROCEDURE weekly_maintenance_task
GO
CREATE PROCEDURE [dbo].[weekly_maintenance_task]
AS
BEGIN

    SET NOCOUNT ON
    DECLARE @timeToRun nvarchar(50)
    SET @timeToRun = '02:30:00'
    DECLARE @dayToRun nvarchar(10)
    SET @dayToRun = 'SUNDAY'


    WHILE 1 = 1
    BEGIN
        WAITFOR time @timeToRun
        BEGIN
            DECLARE @dayOfWeek NVARCHAR(10)
            SELECT @dayOfWeek = CASE DATEPART(weekday, GETDATE())
            WHEN 1 THEN 'SUNDAY'
            WHEN 2 THEN 'MONDAY'
            WHEN 3 THEN 'TUESDAY'
            WHEN 4 THEN 'WEDNESDAY'
            WHEN 5 THEN 'THURSDAY'
            WHEN 6 THEN 'FRIDAY'
            WHEN 7 THEN 'SATURDAY'
            END
            IF (@dayOfWeek = @dayToRun)
            BEGIN
                EXECUTE sp_msforeachdb 'USE ?
                IF DB_NAME() NOT IN (''master'', ''msdb'',''tempdb'',''model'')
                    IF EXISTS (select * from sys.procedures where name=''database_maintenance_weekly'')
                        EXECUTE database_maintenance_weekly'
            END
        END
    END
END

GO

sp_procoption @ProcName = 'weekly_maintenance_task',
              @OptionName = 'startup',
              @OptionValue = 'on'
GO
  • 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-05-26T03:00:42+00:00Added an answer on May 26, 2026 at 3:00 am

    You can use the kill command to kill a session. You can find the right session with dm_exec_requests and sys.fn_get_sql().

    declare @nuke_spid int
    
    select  @nuke_spid = session_id
    from    sys.dm_exec_requests r 
    outer apply sys.fn_get_sql(r.sql_handle) s
    where   s.text like '%dm_exec_requests r%'
    
    exec ('kill ' + @nuke_spid)
    

    This should return Cannot use KILL to kill your own process.

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

Sidebar

Related Questions

I have a maintenance application that has to turn enterprise data (from various databases/tables)
We have set up a SharePoint meeting workspace (using WSS 3.0) for our weekly
I have a situation in which we have two production databases that synchronize with
I have an app that uses several prefixes and, while not frequent, it's also
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
In SQL Server 2005 I have a maintenance plan set up to back up
The examples that I have come across for when new makes sense involve maintenance
I have set up multiple targets in a single xml file. I expect all
I have set up 2 servers which are linked. From my LOCAL SERVER, I
I have :set hlsearch as default value. When I search for something, search terms

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.