all groups > sql server programming > september 2007 >
You're in the

sql server programming

group:

restore database issue


restore database issue Tim Zych
9/22/2007 10:56:39 PM
sql server programming: I have 2 databases in use. One is Dev, the other is Test.

I created a backup of Dev, dev.bak.

When I executed the statement:

restore database Test from disk = 'D:\BackupLoc\dev.bak' with replace

I got a message that said:

"Processed XXX pages for database 'Test', file 'Dev' on etc
RESTORE DATABASE successfully processed xxx pages...

No error occurred, and it looked like the process worked.

But nothing happened to Test. I could see the old stored procedures and old
data. Does it matter that the schema for Test was substantially different
than Dev?

I then used the GUI to replace using the same file (Tasks -> Restore ->
Database). That worked

Then I modified some data in Test, re-ran the exact same restore database
script and it worked this time. I could see that Test had Dev's data.

Why would that happen?

My goal is to dump Test and replace it with Dev. Why would it work the 2nd
time around, after I used the GUI to replace it.

Thanks.



Re: restore database issue Uri Dimant
9/23/2007 12:00:00 AM
Tim
Hmm, WITH REPLACE means fisrt drop database and the restore. Are you sure?

create database test
go
use test
create table t ( c int)
go
insert into t values (1)
go
backup database test to disk ='c:\temp\test.bak'
go
--now insert one more row into t table
insert into t values (2)
select * from t --two rows
--Now restore backup ( we should see only one row)
use master
restore database test from disk ='c:\temp\test.bak' with replace
use test
select * from t --ONLY one row
GO
drop database test





[quoted text, click to view]

Re: restore database issue Tibor Karaszi
9/23/2007 12:00:00 AM
My guess is that you have several backups on that file and you restored an old backup. Use RESTORE
HEADERONLY to investigate the backup file.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi


[quoted text, click to view]
Re: restore database issue Dan Guzman
9/23/2007 12:00:00 AM
[quoted text, click to view]

Schema doesn't matter. BACKUP/RESTORE process physical files so the target
is exactly like the original database. My guess is that your first backup
file contained multiple backups and the first backup (oldest) was restored
by default instead of the intended last (latest) backup.

If INIT isn't specified on the BACKUP command and the backup file already
exists, the new backup is appended to the end of the file instead of
overwriting. You can ensure the backup file contains only a single backup
by specifying the INIT on the BACKUP command like the example below. This
will overwrite the target backup file if it exists.

BACKUP DATABASE DEV
TO DISK = 'D:\BackupLoc\dev.bak'
WITH INIT, STATS=10

--
Hope this helps.

Dan Guzman
SQL Server MVP

[quoted text, click to view]
Re: restore database issue Tim Zych
9/23/2007 12:16:23 AM
100% positive. I ran it from master as you are doing. I tried this 2 nights
in a row and got the same result, until the 2nd night when I used the GUI
and then the sql command.

It's working now though.


[quoted text, click to view]

Re: restore database issue Tim Zych
9/23/2007 10:52:40 PM
You're right. that was it.

Thanks for your input along with Uri and Dan too.

Tim


"Tibor Karaszi" <tibor_please.no.email_karaszi@hotmail.nomail.com> wrote in
message news:55DF2B68-D316-4C30-9044-49A01C879B0C@microsoft.com...
[quoted text, click to view]

AddThis Social Bookmark Button