Alternatives to snapshot functionality, SQL Server Standard

Sunib picture Sunib · Mar 14, 2011 · Viewed 8.1k times · Source

For testing purposes I would like to reset a complete database to a certain state (data and structure). I would like to do this automated. Preferably a command line instruction before I start my tests.

After some searching I discovered that SQL Server offers an great solution for this. Snapshots. After writing a test query I discovered that the standard edition of SQL Server does NOT support this. :-(

Given the fact that I want this to be automated: what are my options? Overwriting the data files immediately doesn't sound like a good option to me...

Some other information:

  • Windows 7
  • Microsoft SQL Server Standard Edition (64-bit), 10.50.1600.1
  • Database size is app. 1 gigabyte
  • This is only meant for testing. So the database is NOT used by other users when I'm returning to my 'snapshot'.
  • More information about snapshots:

Thank you in advance!

Answer

Ben picture Ben · Mar 14, 2011

Detach the MDF file, copy it somewhere, re-attach it.

When you want to reset the database, detatch the MDF, copy the old one over the top, and re-attach it.

Alternatively backup and restore.