Wednesday, May 16, 2012

Attach Adventure Works Sample Databases SQL 2008, SQL 2012

Microsoft provides few sample databases for all SQL versions to work with it.
Search with "adventureworks database download" keyword in google and open the codeplex site and download the required version of your chocie.

The download will provide only MDF file. To attach sample databases, follow the below process

1. Download the MDF to your required location (C:\temp\2012\)
2. Attaching database can be done in two ways
       a) Using T-SQL Syntax
       b) Using GUI

Using T-SQL

CREATE DATABASE [AdventureWorks2012] ON ( FILENAME =N'C:\Temp\2012\AdventureWorks2012_Data.mdf' ) FOR ATTACH

Using GUI

1. Open SSMS
2. Right Click on Databases - Attach
3. Browse and select the MDF File
4. You will find two files in the database details window
            1) MDF File
            2) LDF File --- Not Found
5. You need to select the Not Found Row -- Remove
6. Click OK to attach the database with out LDF file

No comments: