Difference between revisions of "Renaming a SQL Server database"
From Dot2DotCommunications
(Created page with "The following T-SQL script will rename a database: use master go alter database [original] modify name = [renamed] go If someone's using the database, you'll get a m...") |
|||
Line 16: | Line 16: | ||
The database name 'renamed' has been set. | The database name 'renamed' has been set. | ||
+ | |||
+ | It's a good idea to back up the master database after renaming databases. |
Revision as of 08:30, 17 January 2018
The following T-SQL script will rename a database:
use master go alter database [original] modify name = [renamed] go
If someone's using the database, you'll get a message like this:
Msg 5030, Level 16, State 2, Line 4 The database could not be exclusively locked to perform the operation.
If the operation is successful, you'll get something like this:
The database name 'renamed' has been set.
It's a good idea to back up the master database after renaming databases.