Wednesday, August 10, 2016

SQL: 重新命名DB (SQL server 2008 R2)

右鍵database, 選rename時彈出以下錯誤︰

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

The database could not be exclusively locked to perform the operation. (Microsoft SQL Server, Error: 5030)

參考解決方法後就成功了。

use master
ALTER DATABASE BOSEVIKRAM SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE BOSEVIKRAM MODIFY NAME = [BOSEVIKRAM_Deleted]
ALTER DATABASE BOSEVIKRAM_Deleted SET MULTI_USER

No comments: