I would like to be able to abort a specific sql statement if it takes longer than a specified number of seconds. How can I do that?
For example, I would like to do something like:
SET NextStatementTimeOutSeconds = 60
SELECT * FROM MyTable
IF @@LastStatementTimedOut = 1
PRINT 'Statement timed out after 60 seconds'
ELSE
PRINT 'Statement completed in less than 60 seconds'
Please note that I made up NextStatementTimeOutSeconds
and @@LastStatementTimedOut
in order to illustrate what I would like to do.
Thanks for the suggestions. I'm thinking about using such a timeout inside a single sql script/batch like the one above, if possible.
Background: We have several stored procedures that I'd like to be faster than X seconds. So I'd call them one after each other; and if one takes more than X seconds, I'd just abort and print a statement like 'sproc 13 takes too long'. The data varies and I'm trying different index changes, so I'd like to time-test all sprocs after such changes in order to make sure that all of them are below X seconds.