30.06.2013 Views

SQL Server Backup and Restore - Simple Talk

SQL Server Backup and Restore - Simple Talk

SQL Server Backup and Restore - Simple Talk

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Generating testing data<br />

Chapter 3: Full Database <strong>Backup</strong>s<br />

Getting a decent amount of testing data into a database can be a daunting task, especially when the<br />

database becomes much more complex than our example. Red Gate offers a product, <strong>SQL</strong> Data Genera-<br />

tor, which will scan your database <strong>and</strong> table structure to give you a very robust set of options for auto-<br />

matically generating test data. You can also write custom data generators for even the most specific of<br />

projects. See www.red-gate.com/products/<strong>SQL</strong>_Data_Generator/.<br />

Taking Full <strong>Backup</strong>s<br />

We are now set to go <strong>and</strong> we're going to discuss taking full backups the "GUI way," in<br />

SSMS, <strong>and</strong> by using native T-<strong>SQL</strong> <strong>Backup</strong> comm<strong>and</strong>s.<br />

As you work through the backup examples in this chapter, <strong>and</strong> throughout the book, for<br />

learning purposes, you may occasionally want to start again from scratch, that is, to drop<br />

the example database, re-create it, <strong>and</strong> retake the backups. The best way to do this is to<br />

delete the existing backup files for that database, <strong>and</strong> then drop the database in a way that<br />

also clears out the backup history for that database, which is stored in the msdb database.<br />

This will prevent <strong>SQL</strong> <strong>Server</strong> from referencing any old backup information. Listing 3-5<br />

shows how to do this.<br />

EXEC msdb.dbo.sp_delete_database_backuphistory<br />

@database_name = N'DatabaseName'<br />

GO<br />

USE [master]<br />

GO<br />

DROP DATABASE [DatabaseName]<br />

GO<br />

Listing 3-5: Dropping a database <strong>and</strong> deleting backup history.<br />

96

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!