Adventureworks sample database launched with SQL Server 2012 and you can download it from the codeplex.
Given below are the links :
After downloading the appropriate data files lets proceed with the installation :
Installation via T-SQL :
You should copy the data file to any appropriate location but it should not be in the root directory due to the security issue.
If you do so, it generates error.
Step 2 :
Once you download the file, you will notice that it has only data file and not log file. So, we need to write the script given below to create the database and in order to build a new log file, we need to use ATTACH_REBUILD_LOG.
Create Database [AdventureWorks2012] On (FILENAME= N'C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_Data.mdf') For ATTACH_REBUILD_LOG GO
For testing purpose lets put it in the root directory :
Create Database [AdventureWorks2012] On (FILENAME= N'C:\AdventureWorks2012_Data.mdf') For ATTACH_REBUILD_LOG GO
It generates an error :
File activation failure. The physical file name “C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\AdventureWorks2012_Log.ldf” may be incorrect.
Msg 5123, Level 16, State 1, Line 1
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file ‘C:\AdventureWorks2012_log.ldf’.
Msg 1813, Level 16, State 2, Line 1
Could not open new database ‘AdventureWorks2012’. CREATE DATABASE is aborted.
Installation via SSMS :
Should be same as above.
Step 2 :
Right click on the databases and click on Attach. After that click on Add button and browse the file (AdventureWorks2012_Data).
After that, if you press OK button, it will reflect error as given below.
So, you need to select the file name (AdventureWorks2012_log.ldf) having file type “log” and message “Not Found” and press the Remove button.
After that press OK to finish the installation.
Now, you can see the “AdventureWorks2012” database in SSMS.