?
Solved

Restore SQL 2000 database

Posted on 2013-06-16
16
Medium Priority
?
441 Views
Last Modified: 2013-06-18
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?
0
Comment
Question by:ajdratch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 7
16 Comments
 
LVL 71

Expert Comment

by:Qlemo
ID: 39251639
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.
0
 

Author Comment

by:ajdratch
ID: 39251758
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.
0
 

Author Comment

by:ajdratch
ID: 39251781
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'"
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 71

Expert Comment

by:Qlemo
ID: 39251888
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').
0
 

Author Comment

by:ajdratch
ID: 39252014
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'"
0
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 total points
ID: 39252407
You've replaced the DB name, but you need to change the names in single quotes (but not the file names), as you did already correctly for the log file:
sqlcmd -E -S server2k3  -Q "
restore database pldatass from disk='c:\temp\pldatass.bak' with move 'pldist' to
 'c:\sqldata\pldatass.mdf', move 'pldist_log' to 'c:\sqldata\pldatass.ldf'"

Open in new window

0
 

Author Comment

by:ajdratch
ID: 39252882
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?
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39252956
If you used
   restore database pldatass  ...
the database is called pldatass.
0
 

Author Comment

by:ajdratch
ID: 39253075
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
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39253250
Probably you are still looking at the logical name of the datafile. That one has not changed.
0
 

Author Comment

by:ajdratch
ID: 39253429
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?
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39253800
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.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 39254194
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
0
 

Author Comment

by:ajdratch
ID: 39254510
I uploaded the file. Can I copy that database to a new one with the correct name?
Screenshot.JPG
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 39254639
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.
0
 

Author Closing Comment

by:ajdratch
ID: 39257613
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
0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question