露一小脸海洋星's profile星星知我心PhotosBlogLists Tools Help

Blog


    July 14

    存储过程-杀死所有进程恢复数据库

    use master
    go
    CREATE  PROCEDURE BackUp_ByRestore
    (
    @Path Varchar(500)
    )
    AS


     declare @s nvarchar(1000)
     declare tb cursor local for
     select s='kill '+cast(spid as varchar)
     from master..sysprocesses
     where dbid=db_id('Operation')
     
     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
     --还原
     restore database Operation from disk=@Path
     

    GO