标签:
当需要重命名数据库时,遇到错误:Unable to rename [database]. Rename failed for Database. An exception occured while executing a Transact-SQL statement or batch. The database could not be exclusively locked to perform the operation.
Management Studio is telling you that there are connections that it doesn‘t want to mess with.
Or when using sp_renamedb form a query window, you might see this similar error:
The database could not be exclusively locked to perform the operation.
如果你确实想要重命名数据库,而不管是否有在处理的交易,可以使用一下脚本重命名数据库:
1 ALTER DATABASE [old_DB_name] 2 3 SET SINGLE_USER WITH ROLLBACK IMMEDIATE 4 5 GO 6 7 ALTER DATABASE [old_DB_name] 8 9 MODIFY NAME = [new_DB_name] 10 11 GO 12 13 ALTER DATABASE [new_DB_name] 14 15 SET MULTI_USER 16 17 GO
标签:
原文地址:http://www.cnblogs.com/keepmove/p/4885902.html