select * from master.dbo.sysprocesses where dbid=db_id(N'数据库') 不过最简单还是重启一下就好了哦
无法删除数据库 "#Test",因为该数据库当前正在使用--查询分析器中执行下面的语句就行了. use master go declare @dbname sysname set @dbname='DB1' --这个是要删除的数据库库名 declare @s nvarchar(1000) declare tb cursor local for select s='kill '+cast(spid as varchar) from master..sysprocesses where dbid=db_id(@dbname) open tb fetch next from tb into @s while @@fetch_status=0 begin exec(@s) fetch next from tb into @s end close tb deallocate tb exec('drop database ['+@dbname+']')
--将数据库设置为单用户模式.并马上中断其它用户连接 ALTER DATABASE dbname SET SINGLE_USER WITH ROLLBACK IMMEDIATE; GO DROP DATABASE dbname;
不过最简单还是重启一下就好了哦
go declare @dbname sysname
set @dbname='DB1' --这个是要删除的数据库库名 declare @s nvarchar(1000)
declare tb cursor local for
select s='kill '+cast(spid as varchar)
from master..sysprocesses
where dbid=db_id(@dbname) open tb
fetch next from tb into @s
while @@fetch_status=0
begin
exec(@s)
fetch next from tb into @s
end
close tb
deallocate tb
exec('drop database ['+@dbname+']')
ALTER DATABASE dbname SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
GO
DROP DATABASE dbname;
先kill 连接数据库的会话
再删除数据库.或停数据库服务,再启动后删除.
go
drop table 表名这样就哦了