I run a software platform and am thinking of setting up a demo site so that people can login into a pretend site and edit the data, etc…
However I want then the database to ‘reset’ every ‘x hours / days’ is there a way sql server can do this itself? Otherwise I will have to code an application to restore all the table data and that will take a lot of work.
Thanks
Yes, you create a database snapshot of the ‘clean’ state then every hour you revert the ‘dirty’ database from the clean snapshot. See:
While other methods also exists (backup/restore, detach/attach and copy files etc) the snapshot based one is probably the fastest because snapshots are diferential based at the file system (they use Sparse Files). If your database in ‘clean’ state is very small (no data in tables) but then it gets much larger during that one hour then it may be simpler or faster to rely on plain backup/restore.
Also Database Snapshots are only available in Enterprise Edition of SQL Server, so if your demo uses a lower edition (Standard, Web, Express) you must use a backup/restore or an attach/detach and file copy based solution.
Example of a attach/detach file copy based solution:
clean_db.mdfandclean_db_log.ldf.dirty1_db.mdfanddirty1_db_log.ldfclean_db.mdftodirty2_db.mdfandclean_db_log.ldftodirty2_db_log.ldfsp_detach_db'<dbname>';sp_attach_db'<dbname>', 'dirty2_db.mdf', 'dirty2_db_log.ldf';dirty1_db.mdfanddirty1_db_log.ldfThis procedures reduces the downtime between detach and attach by copying the clean files before the detach/attach operation.