防止存储过程同时执行两次 [英] Prevent a Stored Procedure from being executed twice at the same time

查看:46
本文介绍了防止存储过程同时执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于 SQL Server 2000 的存储过程,它在任何给定时刻只能执行一个实例.有什么方法可以检查并确保该程序当前未在执行中?

I have a stored procedure for SQL Server 2000 that can only have a single instance being executed at any given moment. Is there any way to check and ensure that the procedure is not currently in execution?

理想情况下,我希望代码自包含且高效(快速).我也不想做一些事情,比如创建一个全局临时表来检查它是否存在,因为如果该过程由于某种原因失败,它将始终被视为正在运行...

Ideally, I'd like the code to be self contained and efficient (fast). I also don't want to do something like creating a global temp table checking for it's existence because if the procedure fails for some reason, it will always be considered as running...

我已经搜索过了,我认为还没有人问过这个问题.如果是这样,对不起.

推荐答案

是的,有办法.使用所谓的 SQL Server 应用程序锁.

yes there is a way. use what is known as SQL Server Application locks.

是的,这也适用于 SQL Server 2000.

这篇关于防止存储过程同时执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆