반응형
- /**********************************************************************************************
-- Title : [2k5] 데이터베이스 스냅샷(snapshot) 생성 및 삭제
-- Reference : hanbitbook.co.kr
-- Key word : create database as snapshot of 스냅샷 스냅숏
**********************************************************************************************/
use master;
go
drop database testdb1;
go
create database testdb1;
go
use testdb1;
go
create table tbl1 (id int identity, field1 int);
go
insert into tbl1 values (10);
insert into tbl1 values (20);
insert into tbl1 values (30);
go
select * from tbl1;
go
--데이터베이스 스냅샷 생성
create database testdb1_snapshot
on (name = testdb1, -- 데이터베이스파일의논리적이름
filename = 'd:\testdb1_sh.mdf'
)
as snapshot of testdb1; -- 데이터베이스의이름
go
--생성 확인
use testdb1_snapshot;
go
select * from tbl1;
go
insert into tbl1 values (40); --에러 발생
go
--원본 변경 데이터와 스냅샷 데이터 비교
use testdb1;
go
update tbl1 set field1 = field1 * 2;
go
select * from testdb1.dbo.tbl1;
select * from testdb1_snapshot.dbo.tbl1;
go
--스냅샷 db의 원본 db 삭제시
use master;
go
drop database testdb1;
/*
메시지 3709, 수준 16, 상태 1, 줄 1
이 데이터베이스는 데이터베이스 스냅숏 "testdb1_snapshot"에서 참조하므로
삭제할 수 없습니다. 먼저 이 데이터베이스를 삭제하십시오.
*/
go
drop database testdb1_snapshot;
go
drop database testdb1;
go
반응형