急,在线等待

cxyPioneer 2004-07-13 10:09:56
use master
go
if exists (select name from sysobjects where name='killprocess' and type='p')
drop procedure killprocess
go
create procedure killprocess
@dbname char(50),
@@proId int
as
select @@proId = DB_ID(name) FROM sysdatabases where name = @dbname

上面的这个存储过程能不能直接在SQL语句中,实现kill @@proId 进程号杀掉,或者其他方法再用restore database pubs from disk=数据库名字来恢复数据库
...全文
79 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
pbsql 2004-07-13
  • 打赏
  • 举报
回复
完整的如下:
use master
go

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_killspid]
GO

create proc p_killspid
@dbname varchar(200) --要关闭进程的数据库名
as
declare @sql nvarchar(500)
declare @spid nvarchar(20)

declare #tb cursor for
select spid=cast(spid as varchar(20)) from master..sysprocesses where dbid=db_id(@dbname)
open #tb
fetch next from #tb into @spid
while @@fetch_status=0
begin
exec('kill '+@spid)
fetch next from #tb into @spid
end
close #tb
deallocate #tb
go

--用法
exec p_killspid '数据库名'

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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