查找出使用该数据库的进程,然后杀死进程 首先使用USE MASTER 使自己不再访问所要DETACH的数据库 使用 select identity(int,1,1) as ID,spid into @userprocess from master..sysprocesses where db_id=db_id('你的数据库的名字') declare @cunt int declare @maxcount int declare @spid varchar set @count=1 select @maxcount=count(*) from @userprocess while @cunt<=@maxcount begin select @spid=spid from @userprocess where id=@cunt exec('kill '+@spid) end
修正 上面建立临时表改用#userprocess而不是@userprocessselect identity(int,1,1) as ID,spid into #userprocess from master..sysprocesses where db_id=db_id('你的数据库的名字') declare @cunt int declare @maxcount int declare @spid varchar set @count=1 select @maxcount=count(*) from #userprocess while @cunt<=@maxcount begin select @spid=spid from @userprocess where id=@cunt exec('kill '+@spid) end
首先使用USE MASTER 使自己不再访问所要DETACH的数据库
使用
select identity(int,1,1) as ID,spid into @userprocess from master..sysprocesses
where db_id=db_id('你的数据库的名字')
declare @cunt int
declare @maxcount int
declare @spid varchar
set @count=1
select @maxcount=count(*) from @userprocess
while @cunt<=@maxcount
begin
select @spid=spid from @userprocess where id=@cunt
exec('kill '+@spid)
end
上面建立临时表改用#userprocess而不是@userprocessselect identity(int,1,1) as ID,spid into #userprocess from master..sysprocesses
where db_id=db_id('你的数据库的名字')
declare @cunt int
declare @maxcount int
declare @spid varchar
set @count=1
select @maxcount=count(*) from #userprocess
while @cunt<=@maxcount
begin
select @spid=spid from @userprocess where id=@cunt
exec('kill '+@spid)
end