Sql-server – Timeout on CPU usage

sql server

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.

Best Answer

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.