I am writing a script to automate the process of restoring one database using the .bak file of another database. I am getting the error:
The backup set holds a backup of a database other than the existing 'add_BackupDev' database.
The answers I am finding online all appear to have a solution that involves completing the restore manually and not through a script, which is not an option for me.
This is my code. The variable @LastDatabaseRestore is passing in the appropriate file path for my .bak file.
RESTORE DATABASE add_BackupDev
FILE = N'FILENAME'
FROM DISK = @LastDatabaseRestore
WITH FILE = 1,
MOVE 'add_backupDev' TO 'R:\DATA\add_BackupDev.mdf',
MOVE 'add_BackupDev_log' TO 'L:\LOG\add_BackupDev.ldf',
NOUNLOAD,
REPLACE;
GO