By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .
close

恢复数据库的时候遇到这个错误

解决办法

/*
断开所有用户打开的连接
*/
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 sysname --要关闭进程的数据库名
as
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
go

--用法
exec p_killspid 'hj'

--恢复数据库.
RESTORE DATABASE hj FROM disk='D:\hj.dat'

info Last modified by Raymond at 6 years ago
info About author

info License/Terms

Please log in or register to comment. account_circle Log in person_add Register
comment Comments (0)
No comments yet.