question

Therealist avatar image
Therealist asked

How to rename the physical names of the database files?

Hi, I was trying to rename a database and its files to make them look similar to each other,i was successful in renaming database name and logical names of the files but i was not able to rename the physical names of them,after a bit of reading i came to know that there are two ways 1. with XP_CMDSHELL and 2.DETACHING AND ATTACHING THE DB , XP_CMDSHELL is not available for me or i am not much aware dealing with it, I tried below mentioned steps but failed to rename physical names of the file. I renamed database and its logical file names from DB_CORE TO DB_ETL(New name of the database and its logical file name that i want to use further ). After renaming the logical names i have successfully detached and attached the database but the physical names of the files remained same (with old names) the changes i tried to make did not reflect on them, so i am wondering how can i rename the physical names of the files...just physical names of the files... i tried below mentioned way to attach the database after renaming logical files and detaching. USE [master] CREATE DATABASE [DB_ETL] ON ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\DB_ETL.mdf'), ( FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\DB_ETL_log.ldf') FOR ATTACH Query executed successfully but changes did not reflect on the physical names of the files.
database-filesrenamemdfldf
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

perrywhittle avatar image perrywhittle commented ·
You don't need to detach the database, but you do need to offline it to rename the physical OS files. Please see my article on moving\renaming database files at this link and post back if you need any further help http://www.sqlservercentral.com/articles/Files+and+Filegroups/96031/ Regards Perry
0 Likes 0 ·

1 Answer

·
Kev Riley avatar image
Kev Riley answered
You would need to detach, rename the physical files in Windows explorer, then attach referencing the new names.
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.