码迷,mamicode.com
首页 > 数据库 > 详细

SQL 笔记

时间:2015-10-16 18:44:48      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:

当需要重命名数据库时,遇到错误: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

 

SQL 笔记

标签:

原文地址:http://www.cnblogs.com/keepmove/p/4885902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!