Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>Be careful when you use Rename option from context menu</strong> that appear when you right click on the database in Management Studio. This option does not change the database file names. To change logical filenames for DATA and LOG files <strong>you can also use a Management Studio interface but unfortunately sometimes it does not work</strong>.</p> <p><strong>Let’s do it properly... it should works always.</strong></p> <ol> <li><strong>Detach database:</strong> Using Management Studio, right-click on database > go to “Tasks” > “Detach”, click OK to detach a database (note: that the DB can not be used to detach it)</li> <li><strong>Rename Physical files:</strong> Once the database is detached the physical files are unlocked and you can rename them using Windows Explorer: <img src="https://i.stack.imgur.com/3Ai7f.png" alt="enter image description here"></li> <li><p><strong>Attaching database with New Name:</strong> For it use T SQL:</p> <p>USE [master] CREATE DATABASE [SqlAndMe] ON ( FILENAME = N’C:\…\NewName.mdf’), ( FILENAME = N’C:\…\NewName_log.LDF’) FOR ATTACH</p></li> <li><p><strong>Rename Logical file names:</strong> Execute this T SQL:</p> <p>USE [NewName] ALTER DATABASE [NewName] MODIFY FILE (NAME=N’OldName’, NEWNAME=N’NewName’) ALTER DATABASE [NewName] MODIFY FILE (NAME=N’OldName_log’, NEWNAME=N’NewName_log’) SELECT name, physical_name FROM [NewName].sys.database_files</p></li> </ol> <p>It should works!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload