Rename database data file in SQL Server 2005

sql-server-2005, ssms

Solution

Yes, you can do this, as long as you have the right to detach and re-attach the database, and as long as you find a way to physically rename the files on disk:

1) issues these commands

ALTER DATABASE yourdatabase
MODIFY FILE (NAME = logical_file_name, FILENAME = 'your-new-file-on-disk.mdf' )

(as DGGenuine pointed out in a comment: the 'your-new-file-on-disk.mdf' must be a full file name - including path - on your disk)

2) detach the database

3) rename the files on disk

4) re-attach the database again

Problem

I need to rename a databases data file. Is this possible through SQL Server Management Studio? FYI, I do not have permissions to the underlying box. Edit: I also need to change the location of the file.

Original source