您好,登錄后才能下訂單哦!
小編給大家分享一下如何解決sql server:alter database name的問題,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
--step 1 : 修改數(shù)據(jù)庫名稱 USE master GO ALTER DATABASE GeovinDuCms SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO EXEC master..sp_renamedb 'GeovinDuCms','DuCms' GO ALTER DATABASE DB_SHANGHAI SET MULTI_USER GO --step 2 : 查看修改名稱后的數(shù)據(jù)庫邏輯名及物理文件名 USE master GO SELECT name AS [Logical Name], physical_name AS [DB File Path],type_desc AS [File Type], state_desc AS [State] FROM sys.master_files WHERE database_id = DB_ID(N'DuCms') GO --step 3 : 修改數(shù)據(jù)庫邏輯文件名稱 USE master GO ALTER DATABASE DuCms SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO ALTER DATABASE DuCms MODIFY FILE (NAME=N'GeovinDuCms', NEWNAME=N'DuCms') GO ALTER DATABASE DuCms MODIFY FILE (NAME=N'GeovinDuCms_log', NEWNAME=N'DuCms_log') GO ALTER DATABASE DuCms SET MULTI_USER GO --step 4 : 修改數(shù)據(jù)庫物理文件名稱之前先打開xp_cmdshell支持 USE master GO sp_configure 'show advanced options',1 GO RECONFIGURE WITH OVERRIDE GO sp_configure 'xp_cmdshell', 1 GO RECONFIGURE WITH OVERRIDE GO --step 5 : 重命名數(shù)據(jù)庫物理文件名稱 USE [master] GO ALTER DATABASE DuCMS SET OFFLINE WITH ROLLBACK IMMEDIATE GO EXEC xp_cmdshell 'RENAME "E:\2005database\GeovinDuCms.mdf", "DuCms.mdf"' GO EXEC xp_cmdshell 'RENAME "E:\2005database\GeovinDuCms_log.ldf", "DuCms_log.ldf"' GO --step 6 : 將數(shù)據(jù)庫邏輯名稱指向新的物理文件,并將數(shù)據(jù)庫online USE [master] GO ALTER DATABASE DuCMS MODIFY FILE (NAME =DuCms, FILENAME = 'E:\2005database\DuCms.mdf') GO ALTER DATABASE DuCMS MODIFY FILE (NAME =DuCms_log, FILENAME = 'E:\2005database\DuCms_log.ldf') GO ALTER DATABASE DuCMS SET ONLINE --step 7 : 查看全部修改完成后的數(shù)據(jù)庫情況 USE master GO SELECT name AS [Logical Name], physical_name AS [DB File Path],type_desc AS [File Type], state_desc AS [State] FROM sys.master_files WHERE database_id = DB_ID(N'DuCMS') GO --step 8 : 關閉xp_cmdshell支持 USE master GO sp_configure 'xp_cmdshell', 0 GO RECONFIGURE WITH OVERRIDE GO sp_configure 'show advanced options',0 GO RECONFIGURE WITH OVERRIDE GO USE DuCMS GO
看完了這篇文章,相信你對“如何解決sql server:alter database name的問題”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。