How to rename database in multi-user mode

后端 未结 3 1631
后悔当初
后悔当初 2021-02-01 08:30

I am working on SQL SERVER 2008 & 2008 R2. How can I rename a database in multi-user mode? I am using sp_rename but it returns this error:

Msg 15225,

3条回答
  •  渐次进展
    2021-02-01 08:49

    You can't use sp_rename to rename a database - the sp in question would be sp_renamedb. However, that is in line to be removed in a future version of SQL Server and the preferred method is:

    ALTER DATABASE dbname MODIFY NAME = newdbname;
    

    But you can't do this anyway without an exclusive lock on the database.

提交回复
热议问题