STEP BY STEP Guide for Downloading and Attaching SQL Server 2012 Sample Database
There are various ways to get SQL 2012 sample databases from codeplex.
- Download and Execute Database Scripts in SSMs.
- We can download the data file and attach to SQL Server.
Note – All other SQL Server 2012 Sample Database can be downloaded from here.
Solution 1 : Download and Execute Database Scripts in SSMs
STEP 1 – DOWNLOAD AdventureWorks 2012 Data Script
**This is approx 20 MB of file might take couple of second
STPE 2 - Extract the zip file a folder which has some .CSV data files and instawdb.sql, which will import these csv data in sql tables.
STPE 3 - Copy and execute instawdb.sql, in SQL Server management studio, which will create a database and related Schema and other database objects..
Solution2 : Download the data file and attach to SQL Server.
STEP 1 – DOWNLOAD AdventureWorks 2012 Data File
**This is approx 188 MB of file might take couple of second
STEP 2 – ATTACH downloaded SQL Server Adventure Works Sample database for 2012 to SQL Server
Quick note, the file which we downloaded is just a data file, so we can not attach or install this file. We need to manually attach this Data file to SQL Server to build a AdventureWorks Sample Database.
To build a database from a data file, we need to ATTACH Database data file, to attach, Right Click on SSMS >> Database >>> ATTACH
In attach Window Locate a Data file which we downloaded in STEP 1
In the Attach Databases window; We will see that SQL Server informs us that the log file is not found. In order to attach the database without Database LOG File, we need to select the file as highlighted in the below snippet and click the "Remove" button and finally click OK to attach AdventureWorks database without the transaction log file and click OK
This will create a New database to our SQL Server as expected.
Alter natively, Instead of Graphical tool, we can run the following TSQL Script to attach SQL Server 2012 Sample Database, which I like the most and fast.
USE [master] GO CREATE DATABASE [AdventureWorks2008R2] ON ( FILENAME = N'C:\MSSQL\Data\AdventureWorks2008R2_Data.mdf' ), FOR ATTACH_REBUILD_LOG ; GO
This will create SQL 2012 Sample Databases Adventure Works in specified SQL Server.
