操作,接下來完成資料庫的自動遠原功能。
首先關閉所有使用者連線,**如下;
create
proc
killdb
@dbname
varchar
(1000)as
begin
declare
@svarchar(40
)declare
tb cursor
forselectn'
kill '+
cast
(spid
asvarchar
) from
master..sysprocesses
where
dbid
=db_id
(@dbname
)open
tb fetch
next
from
tb into
@swhile
@@fetch_status=0
exec(@s
)fetch
next
from
tb into
@sclose
tbdeallocate
tbend
接下來執行還原:
exec
killdb
'northwind
'--關閉所有使用者連線
exec
xp_cmdshell
'"c:\program files\winrar\unrar.exe" e -df -o+ d:\~temp\northwind.rar d:\~temp\'if
day(
getdate
())=
8begin
restore
database
[northwind
]from
disk='
d:\~temp\northwind.bak
'with
recovery,
replace
, move n
'mxcement_data'to
n'e:\northwind.mdf',
move n
'mxcement_log'to
n'e:\northwind.ldf'--
recovery 無法還原其它日誌檔案
endelse
begin
restore
database
[northwind]
from
disk='
d:\~temp\northwind.bak
'with
norecovery,
replace
move n
'mxcement_data'to
n'e:\northwind.mdf',
move n
'mxcement_log'to
n'e:\northwind.ldf'--
norecovery 可以還原其它日誌檔案
restore
database
[northwind
]from
disk='
d:\~temp\northwind.cha
'with
recovery
end
還原資料庫
use gyjlbigfootmis goif exists select from sysobjects where name kymp 還原資料庫 and type p begin drop procedure kymp 還原資料庫 endgo create procedure kymp 還原資...
資料庫還原
訊息 5133,級別 16,狀態 1,第 1 行 對檔案 d microsoft sqlserver mssql.1 mssql data db camp unit 2.mdf 的目錄查詢失敗,出現作業系統錯誤 3 系統找不到指定的路徑。訊息 3156,級別 16,狀態 3,第 1 行 檔案 db ...
還原資料庫
在還原資料庫時,有時會提示因為資料庫正在使用,所以無法獲得對資料庫的獨佔訪問權 這時需要在還原資料庫之前關閉正在使用資料庫的執行緒。解決方案如下 執行該方案,必須首先定位到master資料庫,然後在分析查詢器中執行以下語句 alter database 資料庫名 set offline with r...