Friday, March 30, 2012

RESTORE WITH REPLACE

Hi all, I am restoring a database just like from BOL
RESTORE DATABASE MyNwind
FROM MyNwind_1
WITH FILE = 1, STATS=10, RECOVERY,
MOVE 'MyNwind' TO 'c:\MSSQL\Data\NewNwind.mdf',
MOVE 'MyNwindLog1' TO 'c:\MSSQL\Data\NewNwind.ldf'
I do have the database MyNwind already, but it
it is restored anyway without any problems or warnings. I though that one
would need to use the REPLACE clause to achieve this.The REPLACE option is not needed when the source and target database names
are the same. From the Books Online:
<Excerpt href="http://links.10026.com/?link=tsqlref.chm::/ts_ra-rz_25rm.htm">
When the REPLACE option is not specified, a safety check occurs (which
prevents overwriting a different database by accident). The safety check
ensures that the RESTORE DATABASE statement will not restore the database to
the current server if:
The database named in the RESTORE statement already exists on the current
server, and
The database name is different from the database name recorded in the backup
set.
REPLACE also allows RESTORE to overwrite an existing file which cannot be
verified as belonging to the database being restored. Normally, RESTORE will
refuse to overwrite pre-existing files.
</Excerpt>
Hope this helps.
Dan Guzman
SQL Server MVP
"Ruski" <Ruski@.discussions.microsoft.com> wrote in message
news:CB543689-E5A9-4253-AF29-01048D208C1C@.microsoft.com...
> Hi all, I am restoring a database just like from BOL
> RESTORE DATABASE MyNwind
> FROM MyNwind_1
> WITH FILE = 1, STATS=10, RECOVERY,
> MOVE 'MyNwind' TO 'c:\MSSQL\Data\NewNwind.mdf',
> MOVE 'MyNwindLog1' TO 'c:\MSSQL\Data\NewNwind.ldf'
> I do have the database MyNwind already, but it
> it is restored anyway without any problems or warnings. I though that one
> would need to use the REPLACE clause to achieve this.
>

No comments:

Post a Comment