Introduction
AdventureWorks is a sample database from Microsoft that simulates a company called Adventure Works Cycles. It is designed to showcase SQL Server's features, making it an excellent tool for learning, testing, and demonstrating SQL. In this guide, you will learn how to download and restore the AdventureWorks 2022 database to SQL Server. This method involves restoring a backup file, which is an efficient way to set up the database and begin exploring its data.
What is AdventureWorks?
AdventureWorks is a sample database frequently used in SQL Server documentation and examples. It represents a fictional manufacturing company and is often used for:
- Training purposes
- Testing SQL queries and concepts
- Demonstrating SQL Server features
AdventureWorks can be used to practice writing SQL queries or to test your database management skills in a safe, controlled environment.
Note: This guide specifically covers the AdventureWorks 2022 version, but earlier versions such as AdventureWorks 2017 and AdventureWorks 2019 are also available. While the process is similar, there may be slight differences between the versions.
Downloading and Restoring AdventureWorks 2022
To restore AdventureWorks 2022 to your SQL Server, follow these steps. First, go to this link: AdventureWorks GitHub Release. In the "Additional OLTP backups and samples" section, download the file AdventureWorks2022.bak.
After downloading, move the AdventureWorks2022.bak file to your SQL Server’s backup folder. For the default SQL Server instance, the folder path is: C:\Program Files\Microsoft SQL Server\MSSQL16.MSSQLSERVER\MSSQL\Backup
Tip: Make sure the folder exists before copying the file.
Open SSMS and connect to your SQL Server.
In SSMS, right-click the Databases folder in the Object Explorer and select Restore Database.
In the Restore Database window, under the Source section, Select Device option instead of Database. then Click the three dots (…) to browse for the backup file.
Click Add to add a new backup file.
Browse to find the AdventureWorks2022.bak file you installed earlier, select it, and click OK.
Ensure that the AdventureWorks2022.bak file is selected and then click OK.
After clicking OK, SQL Server will begin restoring the database. This confirms that you are restoring the correct backup file.
Once the restore process is complete, you will see a success message confirming that the AdventureWorks 2022 database has been successfully restored to your SQL Server.
Verifying the Database
To verify that the database was restored correctly, run this query in SSMS:
-- Query to check if AdventureWorks database is restored successfully SELECT TOP 10 * FROM AdventureWorks2022.Person.Person;
This query will return the first 10 rows from the Person table in the AdventureWorks 2022 database. If you see data, the database was restored correctly and is ready for use.
Conclusion
In this guide, you've learned how to download and restore the AdventureWorks 2022 database to SQL Server. This process allows you to work with a real-world sample database, making it a fantastic tool for testing and learning SQL.
Note on SSMS Version Compatibility: Ensure you're using an updated version of SQL Server Management Studio (SSMS) for a smooth experience, as older versions may have slight differences in the user interface or available features.