Have you ever wanted to install the sample database (AdventureWorks )provided by Microsoft which a lot of the tutorials and books refer to? Well one of my colleagues has started to learn SQL Server so I thought I would knock up a quick guide for him.
The correct classical way is to use T-SQL would be to use the below script which you should adjust for wherever you have located the data/ MDF file.
CREATE
DATABASE
AdventureWorks2012
ON
(FILENAME = 'C:Program FilesMicrosoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATAAdventureWorks2012_Data.mdf')
FOR
ATTACH_REBUILD_LOG ;
Or you could use the simple GUI method and Right click on databases and select Attach.

Then go to the correct path and select the data / MDF file and press OK.

If you use the T-SQL method ensure that you do not have the LDF / Log file in the directory of the data / MDF file otherwise you may encounter an error. Also, when recreating the database from just the data / MDF file you will get the following error message.
File activation failure. The physical file name “C:Program FilesMicrosoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATAAdventureWorks2012_log.ldf” may be incorrect.
New log file ‘C:Program FilesMicrosoft SQL ServerMSSQL11.MSSQLSERVERMSSQLDATAAdventureWorks2012_log.ldf’ was created.
Originally published at https://parvtheitgeek.com on January 14, 2015.