Link to home
Start Free TrialLog in
Avatar of ajdratch
ajdratch

asked on

Restore SQL 2000 database

I have a SQL 2000 server running one database. This database is for historical data only so there are no changes made since the last backup. The database was showing suspect.

I couldn't fix that so I thought I had a brilliant idea.  

I stopped SQL and renamed the MDF an LDF files. I thought I would be able to restore the backup but in 2000, it looks like you have to have an existing database to restore to.

Now I can't re-attach the suspect database, it says the file you've specified is not a valid SQL server database file.

How can I restore a backup to SQL 2000 when the database is no longer attached?
Avatar of Qlemo
Qlemo
Flag of Germany image

Use a T-SQL command:
   restore database YourDB from disk='C:\Path\To\Backup.bak'
That should work even with a not yet existing DB.
Avatar of ajdratch
ajdratch

ASKER

I'm getting closer. I think the original problem was due to the drive the data is on. I get an error message "File 'PLDIST' cannot be restored to 'E:\MSSQL\DATA\PLDATASS.MDF'. Use WITH MOVE to identify a valid location for the file."

I can't figure out how to use WITH MOVE to change the data location to another drive.
This is the syntax I am trying

C:\Program Files\Microsoft SQL Server\90\Tools\Binn>sqlcmd -E -S server2k3  -Q "
restore database pldatass from disk='c:\temp\pldatass.bak' with move 'pldatass'
to 'c:\sqldata\pldatass.mdf' move 'pldatass_log' to 'c:\sqldata\pldatass.ldf'"
If you didn't change the logical names of the DB files, your syntax is almost correct, just a comma missing:
sqlcmd -E -S server2k3  -Q "
restore database pldatass from disk='c:\temp\pldatass.bak' with move 'pldatass'
to 'c:\sqldata\pldatass.mdf', move 'pldatass_log' to 'c:\sqldata\pldatass.ldf'"

Open in new window

Else you'll first have to seee how the logical file names are chosen. The SQL is
restore filelistonly from disk='c:\temp\pldatass.bak'

Open in new window

Then use those names as logical names (instead of 'pldatass' and 'pldatass_log').
When I run the filelistonly it shows pldist for pldatass.mdf and pldist_log for pldatass_log
Logical file 'pldatass' is not part of database 'pldist'.

This is what I ran
C:\Program Files\Microsoft SQL Server\90\Tools\Binn>sqlcmd -E -S server2k3  -Q "
restore database pldist from disk='c:\temp\pldatass.bak' with move 'pldatass' to
 'c:\sqldata\pldatass.mdf', move 'pldist_log' to 'c:\sqldata\pldatass.ldf'"
ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks so much, I ran the command so many ways I didn't realize the last one had the name wrong.

Now the database is mounted but it is called PLDIST. How can I change it to pldatass?
If you used
   restore database pldatass  ...
the database is called pldatass.
I thought I did but I rebooted the server so i don't have the command window up any more to look at what I ran.

I ran EXEC sp_renamedb 'pldist', 'pmdatass'

It said it was successful however the name is still showing as pldist
Probably you are still looking at the logical name of the datafile. That one has not changed.
I am looking in enterprise manager. I tried connect from a client and it can't log into the database pldatass. Does it matter what it shows in enterprise manager?
Can you show us a screenshot from Enterprise Manager?

I'm a little puzzled now. You said the backup is from the same db, but you have changed the db name and location, as we can see. Is the backup from a different server? In that case SQL users will not be available yet.
Does it matter what it shows in enterprise manager?
It only matters if you have not refreshed.  Alternatively just use something like this:
SELECT *
FROM sysdatabases
I uploaded the file. Can I copy that database to a new one with the correct name?
Screenshot.JPG
As I have said, the name of the DB in the restore command determines its name - I don't know why it should show with the original name, unless you have done some more operations without refreshing the list in Enterprise Manager ... You can try again with the restore command, making sure a different DB name is chosen.
Thanks for all your help. To get the name correct in Enterprise manager,  I detached the database and when I re-attached it, I was able to specify the name