Alternate method for renaming a Database in Sql server 2005

Alternate method for renaming a Database in Sql server 2005

Alternate method for renaming a Database in Sql server 2005

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

Leave a Reply


All material @ copyrighted by chrisranjana.com. If you want to link to this article you are welcome to do so. Unauthorized publication is strictly prohibited. This developer tutorial website contains articles by Php programmers , Software developers, Mysql programmers and asp c# programmers. This website also contains ajax tutorials and advanced mysql sql stored procedures and functions tutorials and sample codes.