none
sqlcmd restore gives an error

    Question

  • I am trying to restore a database that no longer exists from a backup file with the following

    sqlcmd -E -S SERVER -d "master" -n -b -Q "RESTORE DATABASE SOPHOS50 FROM DISK = C:\SOPHOS50.bak WITH REPLACE, RECOVERY"

    but I got an error

    C:\Users\Administrator>sqlcmd -E -S SERVER -d "master" -n -b -Q "RESTORE D
    ATABASE SOPHOS50 FROM DISK = C:\SOPHOS50.bak WITH REPLACE, RECOVERY"
    Sqlcmd: Warning: '-n' is an obsolete option and is ignored.
    Msg 102, Level 15, State 1, Server SERVER, Line 1
    Incorrect syntax near 'C:'.
    Msg 319, Level 15, State 1, Server SERVER, Line 1
    Incorrect syntax near the keyword 'with'. If this statement is a common table ex
    pression, an xmlnamespaces clause or a change tracking context clause, the previ
    ous statement must be terminated with a semicolon.

    any idea?

    Saturday, June 15, 2013 11:14 PM

Answers

  • Since ur DB where ur restoring is not present in sql server u have to give location for its mdf and ldf file

    this query will give logical file name

    RESTORE FILELISTONLY
    FROM DISK = 'C:\SOPHOS50.bak'
    go
     then use this script in ur SQLCMD by giving loc of ur mdf and ldf files
    RESTORE DATABASE YourDB
    FROM DISK = 'D:BackUpYourBaackUpFile.bak'
    WITH MOVE 'YourMDFLogicalName' TO 'D:DataYourMDFFile.mdf',
    MOVE 'YourLDFLogicalName' TO 'D:DataYourLDFFile.ldf'


    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers

    Sunday, June 16, 2013 3:58 AM