I'm going to be moving a database from one server to another. Right now the name makes no sense and I'd like to change it. I found a answer here that makes me think it might be relatively simple. My question is three-fold.
1: Is there a reason I shouldn't rename the database? 2: Would the renaming be as simple as
RESTORE DATABASE [NewDatabaseName]
FROM DISK = N'C:\OldDatabaseName.bak'
WITH FILE = 1,
MOVE N'OldDatabaseName' TO N'C:\NewDatabaseName.mdf',
MOVE N'OldDatabaseName' TO N'C:\NewDatabaseName_1.ldf',
NOUNLOAD,
STATS = 10
GO
3: What's this "NOUNLOAD" parameter? I can't find any reference to it in the searching I've done.
1 Answer 1
- Only if you have applications, T-SQL code, synonyms etc. that reference this database by name. If this is not a production environment, you could test this on the existing copy using
ALTER DATABASE ... MODIFY NAME
and seeing what breaks, or just taking the current copy of the databaseOFFLINE
to see what kind of things might be depending on it. If this is production, you better take the old copy of the database offline as soon as you restore the copy as a new name, because your apps etc. could still be connecting to the old database and you wouldn't know. - Close, but I think that the second
MOVE
command should beMOVE N'OldDatabaseName_log'
. Of course this will leave the files named with the old database name; you can do more cleanup to modify those files individually if you want it to be squeaky clean (I think this can be overkill except in cases where I have built automation around the assumption that files are named for their container). NOUNLOAD
is not really relevant today, and you can probably leave it out of allRESTORE
statements going forward. From the old SQL Server 2000 documentation (the last time it appeared fully documented, IIRC):
Specifies that the tape is not unloaded automatically from the tape drive after a RESTORE. NOUNLOAD remains set until UNLOAD is specified. This option is used only for tape devices. If a non-tape device is being used for RESTORE, this option is ignored.
-
Thank you very much. I'm going to test moving the database today and I'll return to mark your answer if it all goes well.Seth– Seth2014年01月30日 13:23:45 +00:00Commented Jan 30, 2014 at 13:23