Click here to Skip to main content
15,900,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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


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
Posted
Comments
Kornfeld Eliyahu Peter 25-May-14 3:29am    
Why physical names are important for you? For SQL it does not matter whet the files called!
aliwpf 25-May-14 6:33am    
because of backup/restore operations.
Kornfeld Eliyahu Peter 25-May-14 6:34am    
Are you backup your SQL using file copy! OMG! Dont'! Ever! Do! That!

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900