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 Administration
 Restoring a Database

Author  Topic 

xrum
Yak Posting Veteran

87 Posts

Posted - 2012-01-27 : 12:04:49
Hi,

I have a database backup that i need to move to a different SQL Server. I do not know the name of the database, when i go to "restore" it asks me what database i want to restore. This is a new database and not currently on the server.

it will not let me go on. when i create a temp database and try to restore it with my .bak file, i get an error saying it contains database other then the one specified (tempDB)

how do i restore a database on a new server from a .bak file?

ditch
Master Smack Fu Yak Hacker

1466 Posts

Posted - 2012-01-27 : 12:11:16
That's because tempdb is a standard system database in sqlserver, consider restoring it to a different name

Duane.
Go to Top of Page

xrum
Yak Posting Veteran

87 Posts

Posted - 2012-01-27 : 12:14:01
i called it something else, but i got the error: the backup set holds a backup of a database other than the existing 'MY_TEST' database
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-01-27 : 12:25:53
You're using the GUI (SSMS) right?

Ever use code to restore a database?



SELECT @@SERVERNAME

-- ***
-- *** Make Sure the Server Name is
-- ***


-- Find the Database file to Restore. Make sure it's on the Server
EXEC master..xp_cmdshell 'dir \\servername\instance\path\*.*'


-- Look at the internal file information
RESTORE FILELISTONLY
FROM DISK = N'\\servername\instance\path\database.BAK'
GO

-- If the DB Exists, Kick everyone out

ALTER DATABASE [database] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO

-- RESTORE The database...this will overlay an existing one, OR Create a new one if not in existence
-- Get the Logical file names from filelistonly

RESTORE DATABASE [database]
FROM DISK = N'\\servername\instance\path\database.BAK'
WITH MOVE 'logical data file' TO '\\servername\instance\datafilepath\database.MDF'
,MOVE 'logical log file' TO '\\servername\instance\datafilepath\database_log.LDF'
, REPLACE
GO

ALTER DATABASE [database] SET READ_WRITE
ALTER DATABASE [database] SET MULTI_USER
GO



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2012-01-27 : 14:19:11
quote:
Originally posted by xrum

i called it something else, but i got the error: the backup set holds a backup of a database other than the existing 'MY_TEST' database



That implies that a database called My_Test exists. Specify a name that does not already exist.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -