给你个简单的,哈哈,进入SQL的时候插入一张表里面存一个1,然后执行完毕时候给他改为0、select * from 记录 where IsEdit=1 IF @@ROWCOUNT = 0 begin Update 记录 set IsEdit=1 处理SQL ---处理完毕的时候 Update 记录 set IsEdit=0 select '可以进行使用……' end else begin select '正在使用中……' end
--连接1 use pubs create proc test as begin tran select * from authors with(paglock,xlock) where au_id='427-17-2319' waitfor delay '00:00:05' commit tranexec test drop proc test--另一连接执行 exec test --只有连接1执行完了,才会执行
有点类似线程同步, 你可以这样模拟实现 搞一个表, 比如tb1(proc_name varchar(50), status int)用来存储要锁定的存储过程的状态. 存储过程的设计如下 Create PROCEDURE PROC_001 AS --检查存储过程是否在运行中 declare @is_running int = 0; select @is_running=status from tb1 where proc_name='PROC_001';if @is_running is null begin insert into tb1 values('PROC_001',0); set @is_running = 0 ; endif @is_running=0 --0表示没有其他的应用调用该存储过程 begin --将标识置为1,模拟加锁 exec('update tb1 set status=1 where proc_name=''PROC_001''');
/*
要运行的处理代码
*/
--处理完毕, 解锁 exec('update tb1 set status=0 where proc_name=''PROC_001'''); endGO 每天回帖有10个可用分^_^
http://hi.baidu.com/bb3852/blog/item/da7a0eceba7b810593457e77.html
这个里面看看吧!
IF @@ROWCOUNT = 0
begin
Update 记录 set IsEdit=1
处理SQL
---处理完毕的时候
Update 记录 set IsEdit=0
select '可以进行使用……'
end
else
begin
select '正在使用中……'
end
use pubs
create proc test
as
begin tran
select * from authors with(paglock,xlock) where au_id='427-17-2319'
waitfor delay '00:00:05'
commit tranexec test
drop proc test--另一连接执行
exec test --只有连接1执行完了,才会执行
这是本质上的。
搞一个表, 比如tb1(proc_name varchar(50), status int)用来存储要锁定的存储过程的状态.
存储过程的设计如下
Create PROCEDURE PROC_001
AS
--检查存储过程是否在运行中
declare @is_running int = 0;
select @is_running=status from tb1 where proc_name='PROC_001';if @is_running is null
begin
insert into tb1 values('PROC_001',0);
set @is_running = 0 ;
endif @is_running=0 --0表示没有其他的应用调用该存储过程
begin
--将标识置为1,模拟加锁
exec('update tb1 set status=1 where proc_name=''PROC_001''');
/*
要运行的处理代码
*/
--处理完毕, 解锁
exec('update tb1 set status=0 where proc_name=''PROC_001''');
endGO
每天回帖有10个可用分^_^