I have written the below SP and getting below error. Could any one please help me finding the error.
create procedure CopyDB(@DBName varchar(100),@Newname varchar(100))
as
DECLARE @FileName AS nvarchar(4000)
set @FileName = 'D:\'+@DBName+'.bak'
/*Backup the database*/
BACKUP DATABASE @DBName
TO DISK = @FileName
WITH CHECKSUM, INIT;
/*to restore it with new name*/
RESTORE database @Newname
FROM DISK = @FileName
with
MOVE @DBName TO 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\'+@Newname+'.mdf',
MOVE @DBName TO 'C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\'+@Newname+'_log.LDF',
CHECKSUM;
Error message is :
Msg 102, Level 15, State 1, Procedure CopyDB, Line 13 Incorrect syntax near ‘+’.
Try this
Autogenerated Script for restoring of my database:
You can see that @DBName in my case have _Data or _Log in the end. I think you need to do te same or generate the script automatically.