Installing a Sample Database

AdventureWorks2022

Posted by: Aubrey W Love on November 27, 2023
Introduction

In this article, we’ll walk through how to install the AdventureWorks2022 sample database, which we’ll be using for future testing and demonstrations throughout this blog and in the companion book "SQL Practice and Interview Questions" (coming soon).
Be sure to review Figures 7–10 carefully, as they highlight optional steps you may choose to customize—such as changing the default data file locations. These adjustments are not required, so feel free to leave the settings as they are if preferred.

A problem that you may encounter when trying to install (restore) the AdventureWorks2022 sample database on a SQL Server 2019 instance, (or older version) is that you recieve an error message like the one in Figure.1.

Figure.1

To overcome this issue, you are going to need to install SQL Server 2022. According to Microsoft, it's the only solution, at the time of this writing. If you haven't done so already, refer back to the article "Install SQL Server 2022 Developer Edition".

Finding the AdventureWorks2022 sample database

You can get a free copy of the AdventureWorks2022 sample database by clicking on this "direct download" link from Microsoft.
AdventureWorks2022 Sample Database
This will open a new dialogue box asking you to save the "AdventureWorks2022.bak" file/program to your computer.
At this point, select a folder to save the file to. It doesn't matter where, just as long as you remember where you saved it.
The file is about 200 mb, so it may take a few seconds to download, depending on your computer and internet speed. On my setup, it took about 20 seconds.


  • example Do not save this file to your "Downloads" folder. It's best to create a "temp" folder on your drive C: or on a second drive in your computer. For this example, I'm saving it to a folder on drive C: called "temp".

Installing (Restoring) the AdventureWorks2022 sample database

This process is pretty easy, but if you know me, you know I'm going to complicate it. (Humor) Open SQL Server Management Studio (SSMS) and connect to your SQL Server 2022 instance.
In your Object Explorer, right-click on "Databases" and select "Restore Database..." from the drop-down menu.

Figure.3

In the dialouge box that opens, select the "Device" radio button (#1) and click on the elipses (#2).

Figure.4

In the next dialouge box, click the "Add" button.

Figure.5

Navigate to the folder where you saved the AdventureWorks2022.bak file.

Figure.6
Click "OK" and click "OK" again on the next dialouge box. This should take you back to "Restore Database" screen as shown below in Figure.7.
Figure.7
Remember back in the SQL Server 2022 instance install article, steps 17 and 21, where I said there was an easier way to change where your data files could be saved in a different folder. Well, here is where you can do that.
  • example As a general rule, you should not save your data files on drive C:. Always save them to another hard drive in your computer. It's also a preferred practice to NOT keep the “mdf” and “ldf” files on the same drive.

If you refer back to Figure.7, you will notice that "pointed out" the "Files" option in the left pane. Click on that and let's change where my data files will be stored.

In the next dialouge box, shown in Figure.8, click on the elipses where the red arrow is in the image.

Figure.8

In the next dialouge box, navigate to the folder where you want to keep your data files. In my example, I am relocating them to a seperate folder on drive E: As you can see in the first red box in Figure.9. E:\SQL_All\SQL_2022_Data
In the second red box area, type the name and extension for sample database file. In my sample, I just used the name "AdventureWorks2022.mdf".

Figure.9

Repeat this process for the log files by clicking on the elipses next to the second line as shown in Figure.10 below.

Figure.10

Remember, the log file name should include the word "log" and the extension should be "ldf". AdventureWorks2022_log.ldf
When you have the folder and file names set, click "OK". If all went well, you should see the following message.

Figure.11

Okay, I know you're ready to jump right in and start querying data, but there are some additional things you really need to know before you start querying and modifying data.
The next rational step is to learn RDBMS and Set Theory. Those are explained in the next article found here.

On a side note, if you really want to start playing, go ahead. If you mess up the data, tables, views, etc. you can always drop your sample database and restore it again at any time. Remember, it's just a sample database.
To drop a database, that is to delete a database, simply type this command "DROP DATABASE AdventureWorks2022;" in the SSMS query editor and run the query. Once the database has been deleted, you can restore the original database as we did at the beginning of this article.



Want to start your own blog or maybe
dip your toes into the world of writting?

Click on the following links.

Qries
HubSpot Website Design Services