或用这个:create proc killspid (@dbname varchar(20)) as begin declare @sql nvarchar(500) declare @spid int set @sql='declare getspid cursor for select spid from sysprocesses where dbid=db_id('''+@dbname+''')' exec (@sql) open getspid fetch next from getspid into @spid while @@fetch_status < >-1 begin exec('kill '+@spid) fetch next from getspid into @spid end close getspid deallocate getspid end --用法 use master exec killspid '数据库名'
as
begin
declare @sql nvarchar(500)
declare @spid int
set @sql='declare getspid cursor for
select spid from sysprocesses where dbid=db_id('''+@dbname+''')'
exec (@sql)
open getspid
fetch next from getspid into @spid
while @@fetch_status < >-1
begin
exec('kill '+@spid)
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end --用法
use master
exec killspid '数据库名'
上面的代码是个存储过程,你把他建在master系统数据库中
2、
如果你会调用过程,就会调用这个过程
3、
这个作用是断开你指定数据库的所有连接,你最好在作业里定在晚上执行,或在不得以的情况下使用
4、
关键是你写的代码,在使用完数据库有断开与数据库的连接!!!