SQL 语句还原SQL Server数据库
生活随笔
收集整理的這篇文章主要介紹了
SQL 语句还原SQL Server数据库
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
/*
斷開(kāi)所有用戶(hù)打開(kāi)的連接
*/
use master--一定要有這個(gè)
goif exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_killspid]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[p_killspid]
GOcreate proc p_killspid--創(chuàng)建存儲(chǔ)過(guò)程
@dbname sysname --要關(guān)閉進(jìn)程的數(shù)據(jù)庫(kù)名
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'--調(diào)用存儲(chǔ)過(guò)程 這里的hj為數(shù)據(jù)庫(kù)名--恢復(fù)數(shù)據(jù)庫(kù).
RESTORE DATABASE hj FROM disk='d:\LQ_db_201112020200.BAK' --備份數(shù)據(jù)的位置--完成后,刪除存儲(chǔ)過(guò)程drop proc p_killspid
轉(zhuǎn)載于:https://www.cnblogs.com/OOAbooke/archive/2011/12/05/2276527.html
總結(jié)
以上是生活随笔為你收集整理的SQL 语句还原SQL Server数据库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: magento tab(easy tab
- 下一篇: AliasDB:简单统一灵活的数据库访问