數據庫快照(atabase snapshot)是一個只讀的,靜態的數據庫視圖。一個數據庫可以有多個數據庫快照,每個數據庫快照在被顯性的刪除之前將一直存在。數據庫快照將保持和源數據庫快照被創建時刻一致,所以可被用來做一些報表。并且由于數據庫快照的存在,我們可以很容易的把數據庫回復到快照創建時刻。
數據庫快照提供了一個把數據庫回復到一個特定時間點的有效途徑。一個數據庫快照將記錄從這個數據庫快照被創建后已經提交的所有事務,這樣你在對數據庫進行錯誤操作后也不會發出“如果上天能夠再給我一次機會的話,我。。。。。。”的感慨。由于是只記錄數據庫發生的改變,也不是在當前的那一時刻數據庫的狀態,所以數據庫文件并不會很大,如下例:
--我們先來為數據庫northwind創建一個數據庫快照,命名為northwind_dbss1200,并讓此數據庫快照的文件存儲在c:/northwind_data_1200.ss文件中
create database northwind_dbss1200 on
( name = northwind, filename =
'c:/northwind_data_1200.ss' )
as snapshot of northwind;
go
--可以看到這個數據庫快照文件的屬性,如下:可以看到現在size on disk為128k
use northwind
go
--現在northwind數據庫進行更新操作
update dbo.customers
set companyname='newegg.com'
--可以看到現在size on disk為384k
--看一下northwind數據庫中被更新的列中存儲的內容是已經被更新過的
select distinct companyname from northwind.dbo.customers
 
--看一下northwind_dbss1200數據庫中被更新的列中存儲的內容還是被更新以前的內容
select distinct companyname from northwind_dbss1200.dbo.customers
--if an error damages a database, you may choose to revert the database to a database snapshot that predates the error. reverting overwrites the original source database with the reverted database.
restore database northwind from
database_snapshot = 'northwind_dbss1200'
go
--確認
select distinct companyname from northwind.dbo.customers
 
--刪除數據庫快照
drop database northwind_dbss1200
從數據庫快照中恢復數據庫到快照創建的時刻
新聞熱點
疑難解答