This article is half-done without your Comment! *** Please share your thoughts via Comment ***
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:
1 2 3 4 5 |
T-SQL Script to detach your database: USE master; GO EXEC sp_detach_db @dbname = 'my_db'; GO |
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:
1 2 3 4 5 6 7 |
USE master GO CREATE DATABASE my_db ON (FILENAME = 'C:\MySQL_Data\my_db_data.mdf'), (FILENAME = 'C:\MySQL_Data\my_db_log.ldf') FOR ATTACH GO |
Leave a Reply