To rename database it is very common to use for SQL Server 2000 user :
EXEC sp_renameDB 'oldDB','newDB'
sp_renameDB syntax will be deprecated in the future version of SQL Server. It is supported in SQL Server 2005 for backwards compatibility only. It is recommended to use ALTER DATABASE MODIFY NAME instead. New syntax of ALTER DATABASE MODIFY NAME is simple as well.
----Create Test Database
CREATE DATABASE Test
GO
----Rename the Database Test to NewTest
ALTER DATABASE Test MODIFY NAME = NewTest
GO
----Cleanup NewTest Database
----Do not run following command if you want to use the database.
----It is dropped here for sample database clean up.
DROP DATABASE NewTest
GO
Reference : Pinal Dave (http://www.SQLAuthority.com), BOL






So, if you rename the old database with the new name and call drop on the test database, won’t that drop the old DB with the new name?
Yes this will drop it.
This is sample example. Not the real time scenario. In real world, you do not need to drop the new database.
Regards,
Pinal Dave (http://www.SQLAuthority.com)
Chris L,
I have updated my post based on your question.
Thanks for suggestion.
Regards,
Pinal Dave (SQLAuthority.com)
most of the time when i need any help i got here everything
and it is not good for me besides it is beneficial for all the DBA community.
you did great job………
how to add contraint in alter query
I renamed some databases since we need to standardize the naming convention. Unfortunately, it broke the SSIS package that used to be working. Somehow, it does not want to save the password even going directly to the configuration file. Any suggestion?
How about the physical name? How do you rename it?
when i am try to rename database it shows me following error msg
Msg 5030, Level 16, State 2, Line 1
The database could not be exclusively locked to perform the operation.
how do i resolve this problem?
Hi Sir
I was able to rename the database..but the logical name of the database didnot get renamed..is there any query to rename the database’s logical name as well
Thank you so much Rich !!!! your seven stpes help me a great deal…