From time to time Sql Server DBA have to change the database name. There can be several reasons to do so, for example durring the restore you assigned temporary name to a database. Another reason is that project for which you developed that database was renamed. From time to time such requirement comes from Management, who developed new naming convention for database names and you are responsible for implementing it.
In Sql Server 2000 for renaming the database we can use sp_renamedb stored procedure, as illustrated in below example. The full syntax for sp_renamedb procedure is sp_renamedb @oldName, @newName
exec sp_renamedb 'mydb', 'mynewdb'
The database name 'mynewdb' has been set.
In Sql Server 2005 and newer, we still can use the sp_renamedb stored procedure but it is recommended to use ALTER DATABASE MODIFY NAME command, as ilustrated in below example. The full syntax for alter command is: ALTER DATABASE oldName MODIFY NAME = newName
ALTER DATABASE mydb MODIFY NAME = mynewdb
The database name 'mynewdb' has been set.
Recent comments
1 year 44 weeks ago