Delete Db and Restore from a Backup.

Quick sql script to create a delete current test db and restore from a backup.  This one is just for tuesday and thursday. This is for a non-dev database, because it gets deleted and restored.
if  exists(select * from sys.databases where name = 'ApplicationDBRestoreTest')
BEGIN
drop database ApplicationDBRestoreTest
END
DECLARE @myDatabaseName VARCHAR(100) = 'ApplicationDB_TTh.BAK'
DECLARE @myDatabasePath VARCHAR(200) = N'\\sqldev\Backups\C-BCT-SQL01\' + @myDatabaseName
RESTORE FILELISTONLY FROM DISK = @myDatabasePath

RESTORE DATABASE ApplicationDBRestoreTest FROM DISK=@myDatabasePath
WITH
   MOVE 'ApplicationDB2005_Data' TO 'F:\SQL Server\TestRestore\ApplicationDBRestoreTest.mdf',
   MOVE 'ApplicationDB2005_Log' TO 'F:\SQL Server\TestRestore\ApplicationDBRestoreTest_log.ldf'
IF @@ERROR <> 0
EXEC ApplicationDB.dbo.spINSERT_ErrorLog_DbBackup @myDatabaseName ,'Restore Database Check','Failed', 'Restore ApplicationDb_TTh'
BEGIN
EXEC msdb.dbo.sp_send_dbmail
@profile_name ='CBackOffice',
@recipients = 'it-alerts@cbackoffice.com',
@body = 'Restore failed',
@subject = @myDatabasePath;
END

Comments

Popular posts from this blog

Asp.net Publishing Broke Site - "App_WebReferences is not allowed because the application is precompiled"

Telerik - Custom Group Footers In RadGrid

Bootstrap Modal Popup is Grayed Out