Sunday, December 29, 2013

How to attach an AdventureWorks database (mdf) file and log (ldf) file?

1. Search and download both (mdf) file and log (ldf) file for the Database version of your choice.

2. For Example: In case of AdventureWorks database for SQL Server 2008 R2 version you have to download 
AdventureWorks2008R2_Data.mdf and AdventureWorks2008R2_log.ldf.

3. Put both the files in a folder on your drive: Suppose C:\Pract\AdventureWorks2008R2_Database\

4. Run this T-SQL Query: (Make sure Master is selected)

CREATE DATABASE AdventureWorks2008R2 ON
(FILENAME 
'C:\Pract\AdventureWorks2008R2_Database\AdventureWorks2008R2_Data.mdf'),
(FILENAME =
'C:\Pract\AdventureWorks2008R2_Database\AdventureWorks2008R2_log.ldf')
FOR ATTACH;

5. Refresh the database instance.

Any Suggestions or Comments are welcome :)  Thank you :)
Paras