首页 > 数据库技术 > 详细

SQL 笔记

时间:2015-10-16 18:43:14      阅读:199      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!