我需要重命名我的一个数据库并尝试这样的查询
ALTER DATABASE Test MODIFY NAME = NewTest
但这会引发错误
Msg 5030, Level 16, State 2, Line 1
The database could not be exclusively locked to perform the operation.
任何人都可以给我任何建议吗?
我需要重命名我的一个数据库并尝试这样的查询
ALTER DATABASE Test MODIFY NAME = NewTest
但这会引发错误
Msg 5030, Level 16, State 2, Line 1
The database could not be exclusively locked to perform the operation.
任何人都可以给我任何建议吗?
Try something like;
USE master
GO
ALTER DATABASE Test
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE
GO
ALTER DATABASE Test MODIFY NAME = NewTest
GO
ALTER DATABASE NewTest
SET MULTI_USER
GO
Be aware of the fact that this may not rename the physical file on the hard drive though.
您需要调查几件事。您收到该错误的原因可能是由于以下一项或多项原因:
您可以尝试强制单用户模式检查 2。
ALTER DATABASE SINGLE_USER ROLLBACK IMMEDIATE.
这将终止与数据库的任何并发连接,从而允许您排除第二个。
你有两个选择: