0

I have changed my hard disk. My all databases are on old hard disk. I have attached my old hard disk as external hard disk. Now how can I attach database files from external hard disk to new installed SQL Server?

5
  • Either by using SQL Server Management Studio (Object Explorer > Databases > Attach), or you can do it with a T-SQL statement, too (using e.g. sqlcmd) Commented Aug 20, 2017 at 8:58
  • msdn.microsoft.com/en-us/library/ms190209(v=sql.105).aspx Commented Aug 20, 2017 at 9:00
  • Or with T-SQL: learn.microsoft.com/en-us/sql/relational-databases/… Commented Aug 20, 2017 at 9:01
  • I have tried SQL Server Management Studio but it cant read files from that directory Commented Aug 20, 2017 at 9:03
  • You need to copy the files to the new server's file system before you can attach them. Commented Aug 20, 2017 at 9:16

2 Answers 2

2

Follow this steps:

  • Copy/Move your files to "Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\".

  • In SSMS, Databases -> Attach

Sign up to request clarification or add additional context in comments.

Comments

1

You could use SQL Server Management Studio to do this:

  1. In SQL Server Management Studio Object Explorer, connect to an instance of the Microsoft SQL Server Database Engine, and then expand that instance.
  2. Right-click Databases and click Attach.
  3. In the Attach Databases dialog box, to specify the database to be attached, click Add; and in the Locate Database Files dialog box, select the disk drive where the database resides and expand the directory tree to find and select the .mdf file of the database;

Source: https://msdn.microsoft.com/en-us/library/ms190209(v=sql.105).aspx

Please note that you need to copy the files to the new server's file system before you can attach them. Thanks marc_s for pointing it out.

8 Comments

I tried this but object Explorer is not showing files in that directory.
And what files are in that directory?
yes files are in that directory. It is data directory of older sql server
I don't understand. Are there .mdf files in that directory?
It has two files of each database, database file and log file. H:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.