sql server:alter database name的問題

一个新手
發布: 2017-10-18 09:57:49
原創
2111 人瀏覽過


--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
GO

USE DuCMS
GO
登入後複製

以上是sql server:alter database name的問題的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!