zoukankan      html  css  js  c++  java
  • SQL 语句还原SQL Server数据库

    /*
    断开所有用户打开的连接
    */
    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 'lq4'--调用存储过程 这里的hj为数据库名
    
    --恢复数据库.
    RESTORE DATABASE hj FROM disk='d:\LQ_db_201112020200.BAK' --备份数据的位置
    
    --完成后,删除存储过程
    
    drop proc p_killspid
  • 相关阅读:
    jsp自定义标签
    用javascript获取屏幕高度和宽度等信息
    解决document.location.href下载文件时中文乱码
    centos7下的ifconfig命令未安装
    vmstat命令
    FPM打包工具使用
    nmap的使用
    检测硬件RDMA卡是否存在
    RDMA卡的检测方法
    硬件RDMA的驱动配置和测试
  • 原文地址:https://www.cnblogs.com/OOAbooke/p/2276527.html
Copyright © 2011-2022 走看看