當rename database 時, 有時會出現elusive lock 問題. 這是因為執行時有其他user 正在使用而令database locked. 解決這個問題, 除了offline database 再rename名, 還可以把database 轉為single user mode 後再 rename, 有關的 SQL command 如下:
USE master; --Set the database to single mode. ALTER DATABASE <<dbName>> SET SINGLE_USER WITH ROLLBACK IMMEDIATE --Try to rename the database. ALTER DATABASE <<dbName>> MODIFY NAME = <<NewDBName>> --Set the database to Multiuser mode. ALTER DATABASE <<NewDBName>> SET MULTI_USER WITH ROLLBACK IMMEDIATE
Leave a Reply