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

  • SEARCH
  • Home
  • 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 8159675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:59:59+00:00 2026-06-06T17:59:59+00:00

I want to call stored procedure from a trigger, how to execute that stored

  • 0

I want to call stored procedure from a trigger,
how to execute that stored procedure after x minutes?
I’m looking for something other than WAITFOR DELAY

thanks

  • 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-06T18:00:01+00:00Added an answer on June 6, 2026 at 6:00 pm

    Have an SQL Agent job that runs regularly and pulls stored procedure parameters from a table – the rows should indicate also when their run of the stored procedure should occur, so the SQL Agent job will only pick rows that are due/slightly overdue. It should delete the rows or mark them after calling the stored procedure.

    Then, in the trigger, just insert a new row into this same table.

    You do not want to be putting anything in a trigger that will affect the execution of the original transaction in any way – you definitely don’t want to be causing any delays, or interacting with anything outside of the same database.


    E.g., if the stored procedure is

    CREATE PROCEDURE DoMagic
        @Name varchar(20),
        @Thing int
    AS
      ...
    

    Then we’d create a table:

    CREATE TABLE MagicDue (
        MagicID int IDENTITY(1,1) not null, --May not be needed if other columns uniquely identify
        Name varchar(20) not null,
        Thing int not null,
        DoMagicAt datetime not null
    )
    

    And the SQL Agent job would do:

    WHILE EXISTS(SELECT * from MagicDue where DoMagicAt < CURRENT_TIMESTAMP)
    BEGIN
        DECLARE @Name varchar(20)
        DECLARE @Thing int
        DECLARE @MagicID int
    
        SELECT TOP 1 @Name = Name,@Thing = Thing,@MagicID = MagicID from MagicDue where DoMagicAt < CURRENT_TIMESTAMP
    
        EXEC DoMagic @Name,@Thing
    
        DELETE FROM MagicDue where MagicID = @MagicID
    END
    

    And the trigger would just have:

    CREATE TRIGGER Xyz ON TabY after insert
    AS
        /*Do stuff, maybe calculate some values, or just a direct insert?*/
        insert into MagicDue (Name,Thing,DoMagicAt)
        select YName,YThing+1,DATEADD(minute,30,CURRENT_TIMESTAMP) from inserted
    

    If you’re running in an edition that doesn’t support agent, then you may have to fake it. What I’ve done in the past is to create a stored procedure that contains the “poor mans agent jobs”, something like:

    CREATE PROCEDURE DoBackgroundTask
    AS
    
         WHILE 1=1
         BEGIN
             /* Add whatever SQL you would have put in an agent job here */
    
             WAITFOR DELAY '00:05:00'
         END
    

    Then, create a second stored procedure, this time in the master database, which waits 30 seconds and then calls the first procedure:

    CREATE PROCEDURE BootstrapBackgroundTask
    AS
        WAITFOR DELAY '00:00:30'
        EXEC YourDB..DoBackgroundTask
    

    And then, mark this procedure as a startup procedure, using sp_procoption:

    EXEC sp_procoption N'BootstrapBackgroundTask', 'startup', 'on'
    

    And restart the service – you’ll now have a continuously running query.

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

Sidebar

Related Questions

I want to call a stored procedure from windows service and after that I
I have a stored procedure that I want to call from within another, and
I want to call oracle10g's stored procedure MyStoredProcedure from my c# .net 4 code
I have a stored procedure. I want to call a function from it. Want
i want to execute a mysql stored procedure from mysql command prompt in phpmyadmin.stored
I have stored procedure that I created in MySQL and want PHP to call
I want to call a webservice from jQuery. How can I do that?
I want to call a controller function from a view. Is that possible in
I want to call a Stored Procedure which takes two parameters(username & password) and
I call a stored procedure via Linq-to-SQL. This stored procedure simply processes data that

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.