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.
If you are using SQL Server, you can set the database to single-user mode to close any open connections and prevent other users from connecting while you are changing the database name. In Object Explorer, expand Databases, right-click the database to rename, and then select Rename.
Open Microsoft SQL Server Management Studio. Connect to the server wherein the DB you want to rename is located. Go to the location that MDF and LDF files are located and rename them exactly as you specified in first two alter commands. If you changed the folder path, then you need to move them there.
Change the logical file for the SQL Server Database To change the logical file name, view the database properties by right click on the database -> properties.
ALTER keyword is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table. Renaming means we are modifying the data. Hence, we will use ALTER – MODIFY.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With