Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Restore Database Script

Author  Topic 

jbrown7232
Starting Member

22 Posts

Posted - 2011-04-21 : 17:51:18
Hello I created a script to drop current database and restore the database with the latest database backup in my backup directory.

My script is not working at the the area here: KYHDb_'+ @Reviseddate

Please help

CREATE PROC usp_SN2_RunJob_DifferentialBackupRestore23
AS
BEGIN

Drop Database KYH_CounselDB

DECLARE @currentDate datetime
DECLARE @Reviseddate VARCHAR(500)
SELECT @currentDate = GETDATE()
SET @Reviseddate = SUBSTRING(CONVERT(VARCHAR(500), convert(VARCHAR, @currentDate, 10) , 120), 0, 6)
SELECT @Reviseddate

RESTORE DATABASE KYHDb
FROM disk = '\\Server1\Sql_Backup\kyServer.spring\full.bak\KYHDb\KYHDb_'+ @Reviseddate +'.bak'
WITH MOVE 'KYHDb' TO 'E:\MSSQL10.MSSQLSERVER\MSSQL\DATA\KYHDb.mdf',
MOVE 'KYHDb_log' TO 'F:\SQL Logs\KYHDb.ldf', stats = 10;

End

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-21 : 18:11:14
CREATE PROC usp_SN2_RunJob_DifferentialBackupRestore23
AS
BEGIN

Drop Database KYH_CounselDB

DECLARE @currentDate datetime
DECLARE @Reviseddate VARCHAR(500)
SELECT @currentDate = GETDATE()
SET @Reviseddate = SUBSTRING(CONVERT(VARCHAR(500), convert(VARCHAR, @currentDate, 10) , 120), 0, 6)
SELECT @Reviseddate

DECLARE @disk nvarchar(256)

SET @disk = '\\Server1\Sql_Backup\kyServer.spring\full.bak\KYHDb\KYHDb_'+ @Reviseddate +'.bak'

RESTORE DATABASE KYHDb
FROM disk = @disk
WITH MOVE 'KYHDb' TO 'E:\MSSQL10.MSSQLSERVER\MSSQL\DATA\KYHDb.mdf',
MOVE 'KYHDb_log' TO 'F:\SQL Logs\KYHDb.ldf', stats = 10;

End

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jbrown7232
Starting Member

22 Posts

Posted - 2011-04-21 : 18:15:45
Tara I wanna marry you!!! Thanks so much
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-04-21 : 18:16:54
Lol.

You're welcome, glad to help.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -