Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Quick restore question

Author  Topic 

im1dermike
Posting Yak Master

222 Posts

Posted - 2009-03-24 : 09:47:27
Should you DROP a database before you restore it? I'm getting errors saying that the MDF file cannot be overwritten because it is being used by the database.

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2009-03-24 : 10:45:12
you can "force restore over existing database" as one of the options.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

im1dermike
Posting Yak Master

222 Posts

Posted - 2009-03-24 : 10:50:38
Are you talking about the "overwrite the existing database" option? I have that set.

I'm doing this in a stored procedure where I pass the new database.

ALTER PROCEDURE [dbo].[RestoreMGSMonthDatabase]
(
@month varchar(100)
)

AS
BEGIN
DECLARE @location1 varchar(1000), @location2 varchar(1000), @location3 varchar(1000), @month_db varchar(100)
SET @month_db = 'MGSDB_' + @month
SET @location1 = 'E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\' + @month_db + '.BAK'
SET @location2 = 'E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\' + @month_db + '.mdf'
SET @location3 = 'E:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\' + @month_db + '_1.ldf'
RESTORE DATABASE [@month_db] FROM DISK = @location1 WITH FILE = 1, MOVE N'MGSDB' TO @location2, MOVE N'MGSDB_log' TO @location3, NOUNLOAD, REPLACE, STATS = 10
END
Go to Top of Page
   

- Advertisement -