Trigger with delay

  • Hello,

    I would like to know if there is a way to create a trigger that will be executed after a certain time, something like:

    CREATE TRIGGER [batch] ON [dbo].[name_of_table]

    FOR UPDATE

    AS

    WAITFOR DELAY '00:00:20'

    EXEC MASTER.dbo.xp_cmdshell 'c:\tests\batch.bat'

    The only problem with this trigger is it is locking any access to other tables.

    I am new in the World of TSQL so if someone could help go forward.

    Thanks in advance

  • Triggers are 'in process' commands - they execute within the same process as the command that invokes them. Adding a delay into a trigger will add a delay, and possible locks due to transactions, to the calling process.

    One way of getting round this is to create a job which executes at a later time and then deletes itself.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply