SHARE
Facebook X Pinterest WhatsApp

SQL Server 2005 – Automating Creation of Database Snapshots

Aug 3, 2005

SQL Server 2005 is packed with many new features. One of the new features that I would like to discuss in this article is Database Snapshots, which are read only static views of a database. SQL Server 2005 allows you to create multiple snapshots on a database. In this article, I would like to demonstrate the creation of database snapshots and automating the creation of database snapshots.


First let’s simulate the whole snapshot creation process.


Step 1


Copy and paste the query below into the Microsoft SQL Server Management Studio’s Query window and execute it. This statement creates the database MyDB.

Create Database MyDB on Primary
(Name =‘Mydb_Data’,
FileName= ‘C:\data\MyDB_Data.Mdf’,
Size=100MB,
MaxSize=200MB,
FILEGROWTH=10%)
Log on
(Name = ‘Mydb_Log’,
FileName= ‘C:\data\MyDB_Log.Ldf’,
Size=30MB,
MaxSize=50MB,
FILEGROWTH=10%);

Step 2


Let us create a table and insert some rows.


Copy and paste the query below into the Microsoft SQL Server Management Studio’s Query window and execute it. This statement creates the table Hubble_Galaxies and inserts 5 rows to the table.

Use MyDB
go
Create table Hubble_Galaxies (Id int, name varchar(100))
go
insert into Hubble_Galaxies values (1,‘MilkyWay’)
insert into Hubble_Galaxies values (2,‘Spiral Galacy NGC 1300’)
insert into Hubble_Galaxies values (3,‘Whirpool Galacy M51’)
insert into Hubble_Galaxies values (4,‘Galaxy NGC 1427A’)
insert into Hubble_Galaxies values (5,‘NGC 3370’)
go

Step 3


Now let’s create a snapshot for the database MyDB.


Copy and paste the query below into the Microsoft SQL Server Management Studio’s Query window and execute it. This statement creates the snapshot MyDB_Snapshot1 for the database MyDB.

use master
go
Create Database MyDB_Snapshot1  on
(Name =‘Mydb_Data’,
FileName= ‘C:\data\MyDB_Data.SS1’)
AS SNAPSHOT of MyDB;
go

This would create a file C:\data\MyDB_Data.SS1 as shown in Figure 1.0




Fig 1.0


Step 4


Now let’s delete some rows from the original database.


Copy and paste the query below into the Microsoft SQL Server Management Studio’s Query window and execute it. This statement deletes two rows from the MyDB database.

use MyDB
go
delete from Hubble_Galaxies where id in (3,5)
go

Recommended for you...

Best Online Courses to Learn SQL
Ronnie Payne
Sep 23, 2022
Best Courses for Database Administrators
Ronnie Payne
Jul 22, 2022
Tip 74 – Changing Cost Threshold for Parallelism
Gregory Larsen
Feb 24, 2021
How Many Databases Can You Name?
Brad Jones
May 11, 2020
Database Journal Logo

DatabaseJournal.com publishes relevant, up-to-date and pragmatic articles on the use of database hardware and management tools and serves as a forum for professional knowledge about proprietary, open source and cloud-based databases--foundational technology for all IT systems. We publish insightful articles about new products, best practices and trends; readers help each other out on various database questions and problems. Database management systems (DBMS) and database security processes are also key areas of focus at DatabaseJournal.com.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.