如何完全重命名数据库? [英] How can rename a database completely?

查看:118
本文介绍了如何完全重命名数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好。

我决定重命名我的数据库。我写如下:

hello.
i decide to rename my database. i write following:

ALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE 

ALTER DATABASE  MyDB modify file(Name=N'MyDB',NewName=N'TaskManager')
go
alter database MyDB modify file(Name=N'MyDB_log',newName=N'TaskManager_log')
go

exec sp_detach_db @dbname=N'MyDB'
go
sp_configure 'xp_cmdshell',1
go
reconfigure with override
go

exec xp_cmdshell 'RENAME "E:\MyDB.mdf","TaskManager.mdf"'
go
exec xp_cmdshell 'RENAME "E:\MyDB_log.ldf","TaskManager_log.ldf"'
go

create database TaskManager ON
(Filename=N'E:\TaskManager.mdf'),
(Filename=N'E:\TaskManager_log.ldf')
for attach
go
alter database TaskManager set multi_user
go





这个脚本重命名我的数据库文件(mdf和ldf)正确。但我的数据库有53个.ndf文件。

他们的名字还没有改变。现在我有两个问题:

1 - 对我的数据库有害吗?(。ndf文件名根据.mdf文件没有改变)

2-如何重命名逻辑名称和物理名称和.ndf文件名同时?

非常感谢



this script renames my database files (mdf and ldf) correctly.but my database has 53 .ndf files.
their names not changed yet. now i have two question:
1-Is it harmfull for my database?(.ndf files names not changed according to .mdf file)
2- how can i rename logical name and physical name and .ndf file name at the same time?
thanks alot

推荐答案

我建​​议你创建另一个数据库并在修改结构后复制数据

您可以创建自己的应用程序来执行此操作
I suggest to you to create another database and copy the data after modify the structure
you could create your own app to do this


这篇关于如何完全重命名数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆