我在master数据库里, 我想用drop database kkk 来删除数据库kkk 时,为什么说数据库当前正在使用中

lettermail4 2003-08-22 09:34:09
我在master数据库里, 我想用drop database kkk 来删除数据库kkk 时,为什么说数据库当前正在使用中?
...全文
75 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
happydreamer 2003-08-22
  • 打赏
  • 举报
回复
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 '数据库名'

pengdali 2003-08-22
  • 打赏
  • 举报
回复
use 另一个库 <<==关键是这个。
pengdali 2003-08-22
  • 打赏
  • 举报
回复
use 另一个库

drop table 你的库

应为你当前正在这个库上,所以会出错。
nboys 2003-08-22
  • 打赏
  • 举报
回复
因为当前有对象被锁定

use master

declare @spid int
select @spid from sysprocesses where dbid=db_id('你的数据库名')
kill @spid

如果有多个琐,那么循环执行上面的程序

然后再:
drop database '你的数据库名'
hjb111 2003-08-22
  • 打赏
  • 举报
回复
当前使用的数据库是因于有其它的应用程序在使用kkk数据库中的数据!所以不能删除!

34,576

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧