数据库快照(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
从数据库快照中恢复数据库到快照创建的时刻
新闻热点
疑难解答