Hello, is it something new in SQL 2005, that you cannot have a GO statement at the end of a restore database command? If I run a statement like below, it fails on teh GO...
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near 'GO'.
But if I remove the GO it works.... I coulda sworn a GO was ok to complete a batch with ANY SQL statements in it?!? Am I doing something stugatz?
Thanks, Bruce
RESTORE DATABASE MyDatabase
FROM DISK = 'E:\SQL\MyDatabase.BAK'
WITH NORECOVERY,
MOVE 'MyDatabase_Data' TO 'E:\SQL\MyDatabase_Data.MDF',
MOVE 'MyDatabase_Log' TO 'E:\SQL\MyDatabase_Log.LDF'
GO
What tool are you using? GO should be parsed out by the tool and never sent to SQL Server itself, but that does not appear to be occurring here.|||Just using the regular ole SQL Server Mgt Studio query window... GO is still set as my delimiter, I checked that... It's not a big deal, just curious to know if I am doing something strange or something is different in SQL 2005... that doesn't allow you to have a GO immediately after a RESTORE? probably the syntax of my RESTORE is wrong somehow?!? Bruce|||No, it worked for me. Have you tried putting another return in there (maybe there is an invalid character)? This should work.
Also you are not trying to EXEC it right? (I am pretty sure you would have said This will cause that error:
exec ('
RESTORE DATABASE MyDatabase
FROM DISK = ''E:\SQL\MyDatabase.BAK''
WITH NORECOVERY,
MOVE ''MyDatabase_Data'' TO ''E:\SQL\MyDatabase_Data.MDF'',
MOVE ''MyDatabase_Log'' TO ''E:\SQL\MyDatabase_Log.LDF''
GO'
)
|||I can't remember clearly...
Isn't it necessary to also RESTORE the Log when you move the file in a database RESTORE.
Code Snippet
RESTORE DATABASE MyDatabase
FROM DISK = 'E:\SQL\MyDatabase.BAK'
WITH
NORECOVERY,
MOVE 'MyDatabase_Data' TO 'E:\SQL\MyDatabase_Data.MDF',
MOVE 'MyDatabase_Log' TO 'E:\SQL\MyDatabase_Log.LDF'
RESTORE LOG MyDatabase
FROM MyDataBase_Log
WITH RECOVERY
With a 'Simple' recovery model, there shouldn't be any additional effort required to restore the log files. However, since you left the database in NORECOVERY mode, it would be necessary to add the RESTORE LOG as I suggested.
With a 'Full' recovery model, you would want to restore the database first, and then restore the log file(s), using RECOVERY on the last log file restore.
I'm glad you found the 'culprit'. Darn non-visible characters sometimes bite us...
No comments:
Post a Comment