开发者

Selectively restoring a database

开发者 https://www.devze.com 2022-12-17 19:41 出处:网络
I have been using this query: BACKUP DATABASE Ren开发者_开发百科talEase TO DISK = \'C:\\RentalEaseBackup\\RentalEase.bak\'

I have been using this query:

BACKUP DATABASE Ren开发者_开发百科talEase
TO DISK = 'C:\RentalEaseBackup\RentalEase.bak'
WITH COPY_ONLY;
GO

To backup my database. Someone deleted something so now I have to restore it from a previous point in time, however I don't want to overwrite new changes (other than the deletions).

What I was thinking I could do it attached the backup to the SQL Server as a new database and then perform the necessary queries to move the few deleted rows over. However, it won't attach the RentalEase.bak file because it says it isn't a primary database file.

How can I attach the database backup so I can run the SQL queries against it?


You have to RESTORE the DB, you can't attach a backup file

RESTORE DATABASE TestDB
    FROM DISK = 'c:\Northwind.bak'
    WITH MOVE 'Northwind' TO 'c:\test\testdb.mdf',
    MOVE 'Northwind_log' TO 'c:\test\testdb.ldf'

Full syntax here


Restore the database to a different database name, and then you can do whatever you want between the two databases (good luck!)


create a new database named RentalEase2, A restore would look like this

RESTORE DATABASE [RentalEase2] FROM  DISK = N'C:\RentalEaseBackup\RentalEase.bak'
WITH  FILE = 1, NOUNLOAD,  STATS = 10
GO
0

精彩评论

暂无评论...
验证码 换一张
取 消