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.
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.
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.
In the dialouge box that opens, select the "Device" radio button (#1) and click on the elipses (#2).
In the next dialouge box, click the "Add" button.
Navigate to the folder where you saved the AdventureWorks2022.bak file.
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.
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".
Repeat this process for the log files by clicking on the elipses next to the second line as shown in Figure.10 below.
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.
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.
