In this article, I have explained from where you can download AdventureWorks sample database and congifure it to use in local SQL server database. Basically, we will be restoring the AdventureWorks sample database in our local SQL server.
Step 1: Download AdventureWorks database
So, this is our first step to download complete sample database of AdventureWorks, there are many SQL server versions of the sample database.
You can download .bak file of your preferred version.
I will be downloading AdventureWorks2016.bak for this tutorial. It is around 46.7Mb in Size.
Other versions are
AdventureWorks2016_EXT.bak (883MB) This is an extended version of AdventureWorks, designed to showcase SQL Server 2016 features
Once you have downloaded it, open the "Downloads" Folders (Where file is downloaded) and copy/paste it in root folder of D: or E: Drive, basically we are doing this, so we don't get any error related to protection rights.
Step 2: Open your SQL server Management Studio and Restore .bak file
Once you have downloaded the above file, open your local SQL server Management Studio, using which we will be restoring the above downloaded .bak file.
Now, right-click on "Databases" and Select "Restore Database"
From the new pop-up, select "Device"-> "Browse" -> "Add" ( From new pop-up)
Click on "Add"-> Navigate to "E:\AdventureWorks.bak" and Select it, Click "Ok" and the again click "Ok"
Once the restore is ready, you will screen like below
Click OK and Database will be restored completely.
Note: If your SQL server version is lower than AdventureWorks Sample database version, it will throw error. For example if you are trying to install AdventureWorks2017.bak on SQL server 2016 or 2012 then you will get error and you will not be able to restore it. To Check your SQL server version check here
Here is the Gif Image of complete process
Add Sample database using .BAK and T-SQL
If you don't want to use above GUI method, you can directly run the T-SQL query
Suppose, your AdventuraWorks.bak file is located in "E:\", then your SQL query would be as below
RESTORE DATABASE AdventureWorks2016 FROM DISK = 'E:\AdventureWorks2016.BAK' GO
If you are getting error when executing above command like below
Directory lookup for the file "C:\Program Files\Microsoft SQL Server\MSSQL13.MSSQL2016RTM\MSSQL\DATA\AdventureWorks2016_Data.mdf" failed with the operating system error 3(The system cannot find the path specified.).
then you need to try to find the location of .mdf and .ldf file, so execute the below command
RESTORE FILELISTONLY FROM DISK = 'E:\AdventureWorks2016.bak'
You will get location of .mdf and .ldf with logical names, use them as below
RESTORE DATABASE AdventureWorks2016 FROM DISK = N'E:\AdventureWorks2016.bak' WITH FILE = 1, MOVE N'AdventureWorks2016_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\AdventureWorks2016_Data.mdf', MOVE N'AdventureWorks2016_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL13.SQLEXPRESS\MSSQL\DATA\AdventureWorks2016_Log.ldf', NOUNLOAD, REPLACE, NOUNLOAD, STATS = 5 GO
then, executing the above command will work and it will restore AdventureWorks2016.bak file.