Detach/Reattach Database

  • Open SQL Server Management Studio.
  • Expand Databases.
  • Right-click the database you want to move to another drive and click Properties 
Machine generated alternative text:Security Server C Replicat Always( Manag Integr New Database.. New Query Script Database as Tasks Policies Facets Start PowerSheII Reports Rename Delete Refresh Properties
  • In the Database Properties window, select Files and scroll over to find the file path for the Database and log files: 
Machine generated alternative text:o Database Properties - SedonaSecurit,' Select a Script Help General Filegoups Database name Options Change Tracking Pemissions use fulkext indexing Extended Properties Database files Logical Name Secufity_dat Secufity_log / Maxsize Unlimit ed :ent Unlimited SedonaSecurtty DESKTOP-QU2EMO\Mark C \SedonaOffice Data C \SedonaOffice Data
  • Make note of this path as you will need to Copy the files from here to move them to the other drive. 
  • Close the Database Properties window. Right-click the Database > Tasks > Detach… 
Machine generated alternative text:Sedc• Security Server 01 Replicati Always Manage Integrati New Database... New Query Script Database as Tasks Policies Facets Start PowerSheII Reports Rename Delete Refresh Properties Detach... Take Offline Bring Online Shrink Back Up... Restore Mirror... Launch Database Mirroring Monitor... Ship Transaction Logs...
  • Click OK to Detach the database. This will allow you to move the database files and will be the start of downtime for the database. 
Machine generated alternative text:Detach Database Select a General DESKTOP-QU2EMO Connection Sedona user View connection orooefties Scnpt Help Databases to detach Database Name QuoteWerks Drop Updat Status Rea Message
  •  Once the database is detached, go to the path you found earlier and copy the DB.mdf and DB.ldf files. 
.36 Sedo naSecurit,'. mdf SedonaSecurity.zip SedonaSecurit,' I .1df State: Shared 4/12/2018 PM 8/21/2017 4/12/2018 PM SQL Server Databa... V.'inRAR ZIP archive SQL Server Databa... 3011,840 KB 803,419 KB 517 lu KB Edit with Notepad* * Scan with Windows Defender... Share Give access to Add to archive... Add to "sedonaoffice data.rar" Compress and email... Compress to "sedonaoffice data.rar" and email Scan with Malwarebytes Anti- Malware Send to Copy
  •  Navigate to the location you want the files and Paste them there. 
  •  Back in SQL Server Management Studio, Right-click on Databases > Attach… 
Databi Securil Server New Database... Attach... Restore Database... Restore Files and Filegroups... Deploy Data-tier Application... Import Data-tier Application... Start PowerSheII Reports Refresh
  • Click Add… 
  • Attach Databases Select a General DESKTOP-QU2EMO Connection Sedona user View connection orooefties Scnpt Help Databases to attach M DF File Location Database details Original File Name ktach As File Type Database Name Current File Path Remove
  • Navigate to the new location of the DB.mdf file, select it, and Click OK. 
kb-attach-db-mgmt-studio-10
  • Click OK in the Attach Databases window. 
kb-attach-db-mgmt-studio-11
  • That's it, the Database is now attached from the new location. You should be able to delete the database files from the old directory if desired now provided the database functions as expected from the new location (which it should, Copying vs. Cutting earlier in the How-To was mostly just a precaution). 
Was this article helpful?
Thank you for your feedback!
User Icon

Thank you! Your comment has been submitted for approval.