今天在删除一个数据库时,一直报错,大意是:此数据库处理单用户模式,尚在连接当中,无法删除(既使将sqlServer停止后再启动也是如此)
USE [master] GO /****** Object: StoredProcedure [dbo].[killspid] Script Date: 03/28/2011 11:01:32 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO --建一个存储过程,断开所有用户连接。 create proc [dbo].[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 GO
先在master中创建一个存储过程,用于干掉所有连接,然后调用
use master
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。