Monday, March 26, 2012

rename physical files?

Is it possible to rename physical MDF and LDF files? I have been searching
the net for a few hours and I thought I got close with an ALTER DB command.
But I got errors. I think that is only for logical names. Anyhow, here is
what I tried:
alter database pre_8live_hc modify file (name = 'restoredb', newname =
'pre_8live_hc')
alter database pre_8live_hc modify file (name = 'restoredb_log', newname =
'pre_8live_hc_log')
This is what I got back:
Server: Msg 5041, Level 16, State 1, Line 1
MODIFY FILE failed. File 'restoredb' does not exist.
Server: Msg 5041, Level 16, State 1, Line 2
MODIFY FILE failed. File 'restoredb_log' does not exist.
The DB name is pre_8live_hc
Filenames are: (logical / physical)
MDF = NTI_hc_data / d:\program files\microsoft sql
server\msssql\data\restoredb.mdf
LDF = NTI_hc_data_log / d:\program files\microsoft sql
server\msssql\data\restoredb_log.mdf
I have seen some stuff about restore with replace and also attachdb, but
could not get definitive answer. And the commands I tried did not work.
Thanks,
Bryan
You can detach the database, move the physical files (and/or rename them)
and then attach the database. If you can't get that to work, show us the
syntax you are using for sp_attach_db and we'll try to see what's wrong.
HTH
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"IT Department" <it@.ntihc.com> wrote in message
news:r6amd.10958$Ae.9201@.newsread1.dllstx09.us.to. verio.net...
> Is it possible to rename physical MDF and LDF files? I have been
> searching the net for a few hours and I thought I got close with an ALTER
> DB command. But I got errors. I think that is only for logical names.
> Anyhow, here is what I tried:
> alter database pre_8live_hc modify file (name = 'restoredb', newname =
> 'pre_8live_hc')
> alter database pre_8live_hc modify file (name = 'restoredb_log', newname =
> 'pre_8live_hc_log')
> This is what I got back:
> Server: Msg 5041, Level 16, State 1, Line 1
> MODIFY FILE failed. File 'restoredb' does not exist.
> Server: Msg 5041, Level 16, State 1, Line 2
> MODIFY FILE failed. File 'restoredb_log' does not exist.
> The DB name is pre_8live_hc
> Filenames are: (logical / physical)
> MDF = NTI_hc_data / d:\program files\microsoft sql
> server\msssql\data\restoredb.mdf
> LDF = NTI_hc_data_log / d:\program files\microsoft sql
> server\msssql\data\restoredb_log.mdf
>
> I have seen some stuff about restore with replace and also attachdb, but
> could not get definitive answer. And the commands I tried did not work.
> Thanks,
> Bryan
>
|||Hi,
Follow kelens method. What you did is to rename the Logicalfile name. TO
rename the logical database name you have to be in that database.
Thanks
Hari
SQL Server MVP
"IT Department" <it@.ntihc.com> wrote in message
news:r6amd.10958$Ae.9201@.newsread1.dllstx09.us.to. verio.net...
> Is it possible to rename physical MDF and LDF files? I have been
> searching the net for a few hours and I thought I got close with an ALTER
> DB command. But I got errors. I think that is only for logical names.
> Anyhow, here is what I tried:
> alter database pre_8live_hc modify file (name = 'restoredb', newname =
> 'pre_8live_hc')
> alter database pre_8live_hc modify file (name = 'restoredb_log', newname =
> 'pre_8live_hc_log')
> This is what I got back:
> Server: Msg 5041, Level 16, State 1, Line 1
> MODIFY FILE failed. File 'restoredb' does not exist.
> Server: Msg 5041, Level 16, State 1, Line 2
> MODIFY FILE failed. File 'restoredb_log' does not exist.
> The DB name is pre_8live_hc
> Filenames are: (logical / physical)
> MDF = NTI_hc_data / d:\program files\microsoft sql
> server\msssql\data\restoredb.mdf
> LDF = NTI_hc_data_log / d:\program files\microsoft sql
> server\msssql\data\restoredb_log.mdf
>
> I have seen some stuff about restore with replace and also attachdb, but
> could not get definitive answer. And the commands I tried did not work.
> Thanks,
> Bryan
>
|||Thanks guys. The sp_attach_db worked. I will have to admit I didn't try
just renaming the physical files. For some reason I thought I had tried
that in the past and I kep getting errors saying the file didn't exist, but
now that I think back, I was trying to delete one of two transaction logs
and it wouldn't attach back without both logs.
Thanks a bunch!
Bryan
"Hari Prasad" <hari_prasad_k@.hotmail.com> wrote in message
news:OeLusr5yEHA.3408@.TK2MSFTNGP10.phx.gbl...
> Hi,
> Follow kelens method. What you did is to rename the Logicalfile name. TO
> rename the logical database name you have to be in that database.
> --
> Thanks
> Hari
> SQL Server MVP
>
> "IT Department" <it@.ntihc.com> wrote in message
> news:r6amd.10958$Ae.9201@.newsread1.dllstx09.us.to. verio.net...
>

No comments:

Post a Comment