共计 1858 个字符,预计需要花费 5 分钟才能阅读完成。
自动写代码机器人,免费开通
丸趣 TV 小编给大家分享一下如何解决 sql server:alter database name 的问题,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
--step 1 : 修改数据库名称
USE master
ALTER DATABASE GeovinDuCms SET SINGLE_USER WITH ROLLBACK IMMEDIATE
EXEC master..sp_renamedb GeovinDuCms , DuCms
ALTER DATABASE DB_SHANGHAI SET MULTI_USER
--step 2 : 查看修改名称后的数据库逻辑名及物理文件名
USE master
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)
--step 3 : 修改数据库逻辑文件名称
USE master
ALTER DATABASE DuCms SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE DuCms MODIFY FILE (NAME=N GeovinDuCms , NEWNAME=N DuCms)
ALTER DATABASE DuCms MODIFY FILE (NAME=N GeovinDuCms_log , NEWNAME=N DuCms_log)
ALTER DATABASE DuCms SET MULTI_USER
--step 4 : 修改数据库物理文件名称之前先打开 xp_cmdshell 支持
USE master
sp_configure show advanced options ,1
RECONFIGURE WITH OVERRIDE
sp_configure xp_cmdshell , 1
RECONFIGURE WITH OVERRIDE
--step 5 : 重命名数据库物理文件名称
USE [master]
ALTER DATABASE DuCMS SET OFFLINE WITH ROLLBACK IMMEDIATE
EXEC xp_cmdshell RENAME E:\2005database\GeovinDuCms.mdf , DuCms.mdf
EXEC xp_cmdshell RENAME E:\2005database\GeovinDuCms_log.ldf , DuCms_log.ldf
--step 6 : 将数据库逻辑名称指向新的物理文件,并将数据库 online
USE [master]
ALTER DATABASE DuCMS MODIFY FILE (NAME =DuCms, FILENAME = E:\2005database\DuCms.mdf)
ALTER DATABASE DuCMS MODIFY FILE (NAME =DuCms_log, FILENAME = E:\2005database\DuCms_log.ldf)
ALTER DATABASE DuCMS SET ONLINE
--step 7 : 查看全部修改完成后的数据库情况
USE master
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)
--step 8 : 关闭 xp_cmdshell 支持
USE master
sp_configure xp_cmdshell , 0
RECONFIGURE WITH OVERRIDE
sp_configure show advanced options ,0
RECONFIGURE WITH OVERRIDE
USE DuCMS
GO
看完了这篇文章,相信你对“如何解决 sql server:alter database name 的问题”有了一定的了解,如果想了解更多相关知识,欢迎关注丸趣 TV 行业资讯频道,感谢各位的阅读!
向 AI 问一下细节
正文完