restore database with created new database

  • hi guys

    I created a new database

    and want to recover data from a backup

    this script

    use master

    go

    restore database new

    from disk='D:ew.bak'

    go

    but get an error

    Message 3141, Level 16, State 0, Line 1

    The database to be restored was named 'ats342'. Reissue the statement using the WITH REPLACE option to overwrite the 'new' database.

    Message 3013, Level 16, State 1, Line 1

    RESTORE DATABASE is terminating abnormally.

  • You can either do this through management Studio (see attachement) but you need to tick the replace option.

    Alternatively you can use something along the line of :-

    RESTORE DATABASE [PayRoll] FROM DISK = N'C:\SQL Backup\oldDatabase.bak' WITH FILE = 1, MOVE N'GoodData52' TO N'C:\SQL Data\PayRoll.mdf', MOVE N'GoodData52_log' TO N'C:\SQL Data\PayRoll.LDF', NOUNLOAD, REPLACE, STATS = 10

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • Hi. You don't actually need to create a new database before you do the restore, so you could drop the one you created, which would simplify things.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply