Sometimes it is useful to rename a SQL Server 2000 Database.
Typical scenarios include:
- Moving a development database into production.
- Redirecting the front-end of an application to a different version of the back-end.
You cannot rename a database within Enterprise Manager. Instead, you can execute a command in Query Analyzer.
You use sp_renamedb to rename the database:
EXEC sp_renamedb ‘<old name>’, ‘<new name>’
- The command must be executed by a member of the ‘sysadmin’ fixed server role.
- The database must be renamed in ‘single-user’ mode.
- You must be in the master database to execute sp_renamedb.
To rename ‘oldName’ to ‘newName’:
EXEC sp_dboption oldName, ‘Single User’, True
EXEC sp_renamedb oldName, newName
EXEC sp_dboption newName, ‘Single User’, True
- You should ensure that there are no references to the old database name in the database that is renamed.
- The names of the database files / filegroups will not be changed as a result of renaming the datbase.