Is there any way, in SQL Server, to cause a batch to time out if its CPU usage exceeds some value specified in the batch? I need this to occur at the batch, and not the connection level.

  • 1
    How exactly do you specify a batch? One command, or a "true" batch (what was sent from the client to the server for parsing, optimization and execution)? – Tibor Karaszi Oct 12 '20 at 14:51

There has been a quick and dirty method in SQL Server for 20 plus years - you set the value of Query governor cost threshold to your arbitrary amount and then if the estimated cost of the execution plan exceeds that the query is rejected - I believe the end user receives some kind of error message but I haven't seen this enabled in the wild for a VERY long time so can't remember any details.

NB: more than just CPU costs is included from the link : CPU time, memory, and disk IO.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.