Difference between revisions of "Renaming a SQL Server database"

From Dot2DotCommunications
Jump to: navigation, search
(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...")

Revision as of 09:29, 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.