我曾经使用过的所有 RDBMS 访问层都提供了一种取消方法来异步取消正在运行的查询。检查文档以了解您正在使用的任何数据访问技术堆栈。.NET/ADO/JDBC 提供“取消”方法。ODBC - SQLCancel。显然底层RDBMS厂商的数据访问驱动也必须实现该方法。
In terms of usefullness of cancellation I would tend to be critical of any scheme that made regular use of it. In my opinion better coordination and or design would tend to mitigate non-administrative need.
There is significant dependance on the internals of the RDBMS, nature of the transaction and isolation scheme. If the RDBMS uses an optimistic concurrency model (ie commit is essentially free) canceling a running query can involve a potentially expensive rollback operation. In a worst case a query running for an hour up to the point of cancellation may very well take another hour to rollback.