用存储过程还原数据库
生活随笔
收集整理的這篇文章主要介紹了
用存储过程还原数据库
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
if exists(select name from sysobjects where name='usp_restoredb')
? drop proc usp_restoredb
go
/*
exec usp_restoredb "library","D:\dbbak.bak"
*/
create proc usp_restoredb
(
? @dbname? varchar(255),?? --數(shù)據(jù)庫(kù)名字
? @filepath varchar(255)??? --文件路徑
)
as
set nocount on
--exec ('use master go')
exec ('alter database '+@dbname+' set offline WITH ROLLBACK IMMEDIATE')
exec ('restore database '+@dbname+' from disk=" '+@filepath+'" with REPLACE')
exec ('alter database '+@dbname+' set online with rollback IMMEDIATE')
if @@error<>0
begin
? select 'F','數(shù)據(jù)庫(kù)恢復(fù)失敗'
? return
end
else
begin
? select 'T','數(shù)據(jù)庫(kù)恢復(fù)成功'
? return?
end
? drop proc usp_restoredb
go
/*
exec usp_restoredb "library","D:\dbbak.bak"
*/
create proc usp_restoredb
(
? @dbname? varchar(255),?? --數(shù)據(jù)庫(kù)名字
? @filepath varchar(255)??? --文件路徑
)
as
set nocount on
--exec ('use master go')
exec ('alter database '+@dbname+' set offline WITH ROLLBACK IMMEDIATE')
exec ('restore database '+@dbname+' from disk=" '+@filepath+'" with REPLACE')
exec ('alter database '+@dbname+' set online with rollback IMMEDIATE')
if @@error<>0
begin
? select 'F','數(shù)據(jù)庫(kù)恢復(fù)失敗'
? return
end
else
begin
? select 'T','數(shù)據(jù)庫(kù)恢復(fù)成功'
? return?
end
總結(jié)
以上是生活随笔為你收集整理的用存储过程还原数据库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 红衣大炮的飞秋实现原理
- 下一篇: [飞秋]局域网聊天写的代码旁人从来看不