SQL Server: Move your database using Attach and Detach

In this post, I am going to share necessary steps to move your database from one server to another using Attach and Detach.
There are multiple ways for this exercise like using database backup file, using COPY command, moving data files and log files and others.

But if you want to move your database completely, you can use Attach and Detach in SQL Server.
What you need to do is, just detach your database, copy the database files, paste those files in your new location and attach it in your destination location.

Step 1:

Step 2:

Copy the database files (.mdf,.ndf,.ldf) and paste into new location. Also, check the windows permission for those files.

Step 3:
T-SQL Script to attach your database:

Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz