SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP


How to Create a SQL Server 2005 Database Snapshot


Microsoft SQL Server Database Administrators has a new feature with the Microsoft SQL Server 2005 Edition which is database snapshots.
Database snapshot is new with MS SQL Server 2005 and only available with Microsoft SQL Server 2005 Enterprise Edition.
SQL Server database administration and database development with SQL Server especially for SQL Reporting will be easier with MS SQL Server database snapshots.

A database snapshot can be described as a photo of a database.
Database snapshots are read-only so we can easily say that their main usage areas cover mostly the reporting applications.
Database snaphots are one to one the same of the original database at the time when the snapshot is created.
After a snapshot is created it stays as a static view of the original database at the time of snapshot creation.
A snapshot can persists until it is dropped using DROP DATABASE command.
Also multiple snapshots can be created with different names of a database called as source database.

In order to create a MS SQL Server database snapshot, CREATE DATABASE statement is used.





Microsoft SQL Server Database Snapshot Example


Here is a sample database snapshot create script of the sample database AdventureWorks

First, in order to place the data files of the snapshot, we should define the physical path of the container folder

We can use the source database 's data folder for the same purpose for snapshot database

select physical_name from sys.database_files WHERE file_id = 1
Code

The above query will display where the .mdf file exists. So we can use the same folder.
I'm going to use "D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\"

Considering the below note from Books On Line;

When you create a database snapshot, the CREATE DATABASE statement cannot reference log files, offline files, restoring files, and defunct files.

I run the below select statement to get a list of data files that I should reference

select name from sys.database_files WHERE type_desc = 'ROWS'
Code

The returned row set only contains the "AdventureWorks_Data"

Now, we are ready to create a snapshot of the source database.

CREATE DATABASE AdventureWorks_SS ON
(
NAME = AdventureWorks_Data,
FILENAME = 'D:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.ss'
)
AS SNAPSHOT OF AdventureWorks
Code

After the above command is completed successfully, we can see the snapshot database in the Database Snapshots folder of the SQL Server Instance

SQL Server Database Snapshot

In order to delete or remove a database snapshot after it is not needed any more, you can DROP it by using the DROP DATABASE command.


DROP DATABASE AdventureWorks_SS
Code

Note that if database snapshot creation fails, the snapshot is in suspect status and it should be deleted or dropped.

I believe, sql server programmers as well as database administrators will benefit more from Microsoft database snapshots.
Especially when MS SQL Server performance is an issue. Than Microsoft SQL Server snapshots can be a solution especially for distinguishing reporting databases from the transactional production databases.
Administrators or developers do not need to backup and restore SQL databases for creating a second database for MS SQL Server Reporting Services, for instance.

For additional tutorials on creating SQL databases please refer to SQL tutorial titled How to Create a Database in SQL Server 2005.



SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.