Nisarg Upadhyay
Database install script

Install and configure the AdventureWorks2016 sample database

January 9, 2020 by

This article explains the process of installing the AdventureWorks2016 and AdventureWorksDW2016 sample database on a stand-alone instance of SQL Server and Azure SQL Server. The sample databases were published by Microsoft to demonstrate how to design a database using SQL Server. Microsoft has also published another lightweight database named AdventureworksLT, which can be used as a sample database on Azure SQL Server.

Installing sample databases on stand-alone SQL instance

To install AdventureWorks2016 and AdventureWorksDW2016 databases, you must install SQL Server Express/Standard/Enterprise Edition and SQL Server Management Studio.

On the stand-alone SQL instance, both databases can be installed by the following methods:

  1. Direct download and restore the full backup of the database
  2. Download the install scripts from GitHub and build the database by executing the script

Install Adventureworks2016 using the full backup

First, let us install the database using the backup file. You can download the AdventureWorks sample database from the following links:

Once the backup is downloaded, open SQL Server Management Studio and from Object Explorer, expand database engine, right-click on Databases and select Restore Database. See the following image:

In the Restore Database window, select Device as a source and click on ellipse (…):

Restore database dialog box

In the Locate backup devices window, select the backup media by clicking Add, and then in the newly opened window navigate to the directory where the database backup is downloaded and select the backup (.bak) file. Click OK:

Nevigate the backup file location

If you want to change the physical location of the data file and log file, click on Files pane and change the target location for the data and log files. Note that it is best practice to keep data files and log files on separate drives:

Change the destination of data file and log file

Click OK. It will initiate the database restoring process. Once the database restores successfully, a popup appears stating that the database has been restored successfully. See the following image:

Database has been restored

Now, our database has been restored, and we can connect it using the SQL Server Management Studio. See the following image:

AdventureWorks2016 database in Object explorer

Similarly, you can download the AdventureWorksDW2016 from the links below and install it by restoring the database on SQL Server stand-alone instance.

You can download the AdventureWorks data warehouse database from the following links:

Build a database by executing the installation scripts

We can also prepare the database by executing the database installation script on SQL Server. To do that, first, you must download the installation scripts of AdventureWorks2016 and AdventureWorksDW2016 databases. You can download the installation scripts of the AdventureWorks OLTP database from AdventureWorks-OLTP-install-script.zip or use the files in the OLTP-install-script GitHub folder.

Once files are downloaded, extract those files using WinRar or any other data compression tool. After extracting the files, execute the following steps:

  1. Enable the SQL Server full-text search feature
  2. Copy the installation script and other files to “C:\AWorks2016Database\” directory
  3. Open the “instawdb.sql” file in SQL Server Management Studio
  4. Change the value of the environment variable SqlSamplesSourceDataPath to “C:\AWorks2016Database\

    :setvar SqlSamplesSourceDataPath “C:\AWorks2016Database\”

  5. Change the value of the environment variable DatabaseName to “AdventureWorks2016_InstallScript

    :setvar DatabaseName “AdventureWorks2016_InstallScript

  6. To execute the scripts, we must enable the SQLCMD mode in SSMS. To do that, click on Query menu and select SQLCMD Mode. See the following image:

    Enable SQLCMD mode

  7. Click on Execute or Press F5 to run the script

    The script will create all the database objects and add them to the tables

    Database install script

Once the script is executed successfully, you can see the AdventureWorks2016_InstallScript database in Object Explorer of SQL Server Management Studio. See the following image:

Database AdventureWorks2016_InstallScript has been install

Similarly, to install AdventureWorksDW2016, you must download the installation scripts. You can download the installation script of the AdventureWorks OLAP database from AdventureWorksDW-data-warehouse-install-script.zip or use the files in data-warehouse-install-script Github folder. To install the AdventureWorksDW2016 database, follow the same process, which I explained above.

Installing sample databases on Azure SQL Server

To install the sample database on Azure SQL Server, you must create a SQL Server resource group with the AdventureWorksLT database. To do that, log in to the Microsoft Azure portal, and on the home screen, click on Create a resource. See the following image:

Create new resource on Azure Portal

On the next screen, click on SQL Database. See the following image:

Create new SQL Database on Azure Portal

On the next screen, fill the details of subscription, resource group, name of the database, and name of the server and type of compute + storage. Click Next. See the following image:

Basics screen on Azure Portal

In the Additional settings menu, choose Sample from the Use existing data option under the Data source section. Click Review + create. See the following image:

Additions settings screen on Azure Portal

In the Review + create step, verify the configuration, and click on Create:

Review and create screen on Azure Portal

SQL Database Deployment process will start. It will take a couple of minutes. Once the deployment process completes, you will be able to connect to the database from the SQL Server Management Studio. See the following image:

AdventureWorksLT database

Summary

In this article, I have explained how we can install the AdventureWorks2016 sample database on SQL Server stand-alone instance using full backup and installation scripts. Moreover, I have also installed the AdventureWorksLT database on Azure SQL Server.

Nisarg Upadhyay
168 Views