Figured it out by using SQL Server Agent and SQL procedures.
This is basically how my code is built up now:
Make the temporary change in the table
UPDATE table SET column = 'temp_value' WHERE column = 'normal_value'
Check if the procedure is there, if so, delete it. Create a procedure to revert the changes in the table.
IF EXISTS ( SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'myRevertProcedure')
AND type IN ( N'P', N'PC' ) )
DROP PROCEDURE myRevertProcedure
CREATE PROCEDURE myRevertProcedure
AS
BEGIN
WAITFOR DELAY '00:30:00'
UPDATE table SET column = 'normal_value' WHERE column = 'temp_value'
END
I've created a job in the SQL Server Agent that runs the following:
IF EXISTS ( SELECT *
FROM sys.objects
WHERE object_id = OBJECT_ID(N'myRevertProcedure')
AND type IN ( N'P', N'PC' ) )
BEGIN
EXEC MyProc
DROP PROCEDURE myRevertProcedure
END
The reason the job does not simply revert the change itself is because the user shall set the delay.
If the delay were allways to be 30 mins, I could've made the job run the following:
IF EXISTS (SELECT * FROM table WHERE column = 'temp_value')
BEGIN
WAITFOR DELAY '00:30:00'
UPDATE table SET column = 'normal_value' WHERE column = 'temp_value'
END
By doing this, I would not need any procedure.
BTW: The job runs every few seconds.