sql server:alter database name
生活随笔
收集整理的這篇文章主要介紹了
sql server:alter database name
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
--step 1 : 修改數據庫名稱
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 : 查看修改名稱后的數據庫邏輯名及物理文件名
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 : 修改數據庫邏輯文件名稱
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 : 修改數據庫物理文件名稱之前先打開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 : 重命名數據庫物理文件名稱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 : 將數據庫邏輯名稱指向新的物理文件,并將數據庫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 : 查看全部修改完成后的數據庫情況
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
GOUSE DuCMS
GO
轉載于:https://www.cnblogs.com/geovindu/p/7683062.html
總結
以上是生活随笔為你收集整理的sql server:alter database name的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: STL的Vector, List and
- 下一篇: iptables 网址转译 (Netw