[代码实例][sqlserver]关闭连接。
if exists
(
select *
from master.sys.databases
where name='educationdb'
)
begin
declare @spid varchar(20)
declare curdblogin cursor for
select cast(spid as varchar(20)) as spid
from master.sys.sysprocesses
where dbid=db_id('educationdb');
open curdblogin;
fetch next from curdblogin into @spid;
while @@fetch_status=0
begin
if @spid!=@@spid
exec('kill ' + @spid)
fetch next from curdblogin into @spid
end
close curdblogin;
deallocate curdblogin;
drop database educationdb;
end
go