AdventureWorks 示例数据库AdventureWorks sample databases
06/16/2020
本文内容
适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions) Azure SQL 数据库Azure SQL DatabaseAzure SQL 数据库Azure SQL Database Azure SQL 托管实例Azure SQL Managed InstanceAzure SQL 托管实例Azure SQL Managed Instance Azure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse Analytics 并行数据仓库Parallel Data Warehouse并行数据仓库Parallel Data Warehouse适用于:Applies to: SQL ServerSQL Server(所有支持的版本)SQL ServerSQL Server (all supported versions) Azure SQL 数据库Azure SQL DatabaseAzure SQL 数据库Azure SQL Database Azure SQL 托管实例Azure SQL Managed InstanceAzure SQL 托管实例Azure SQL Managed Instance Azure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse AnalyticsAzure Synapse Analytics 并行数据仓库Parallel Data Warehouse并行数据仓库Parallel Data Warehouse
本文提供了下载 AdventureWorks 示例数据库的直接链接,以及用于将它们还原到 SQL Server 和 Azure SQL 数据库的说明。This article provides direct links to download AdventureWorks sample databases, as well as instructions for restoring them to SQL Server and Azure SQL Database.
有关示例的详细信息,请参阅 示例 GitHub 存储库。For more information about samples, see the Samples GitHub repository.
先决条件Prerequisites
下载备份文件Download backup files
使用以下链接下载适用于你的方案的相应示例数据库。Use these links to download the appropriate sample database for your scenario.
OLTP 数据适用于最典型的联机事务处理工作负荷。OLTP data is for most typical online transaction processing workloads.
数据 仓库 (DW) 数据用于数据仓库工作负荷。Data Warehouse (DW) data is for data warehousing workloads.
轻型 (LT) 数据是 OLTP 示例的轻型 pared 版本。Lightweight (LT) data is a lightweight and pared down version of the OLTP sample.
如果你不确定需要的内容,请从与你的 SQL Server 版本相匹配的 OLTP 版本开始。If you're not sure what you need, start with the OLTP version that matches your SQL Server version.
其他文件可直接在 GitHub 上找到:Additional files can be found directly on GitHub:
还原到 SQL ServerRestore to SQL Server
您可以使用该 .bak 文件将您的示例数据库还原到您的 SQL Server 实例中。You can use the .bak file to restore your sample database to your SQL Server instance. You can do so using the RESTORE (Transact-SQL) command, or using the graphical interface (GUI) in SQL Server Management Studio or Azure Data Studio.
如果不熟悉如何使用 SQL Server Management Studio (SSMS) ,可以参阅 连接 & 查询 开始使用。If you're not familiar using SQL Server Management Studio (SSMS), you can see connect & query to get started.
若要在 SQL Server Management Studio 中还原数据库,请执行以下步骤:To restore your database in SQL Server Management Studio, follow these steps:
.bak从 "下载备份文件" 部分中提供的链接之一下载相应的文件。Download the appropriate .bak file from one of links provided in the download backup files section.
将该 .bak 文件移动到 SQL Server 的备份位置。Move the .bak file to your SQL Server backup location. 这不同于安装位置、实例名称和 SQL Server 版本。This varies depending on your installation location, instance name and version of SQL Server. 例如,SQL Server 2019 的默认实例的默认位置是:For example, the default location for a default instance of SQL Server 2019 is:
C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup.C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup.
打开 SQL Server Management Studio (SSMS) 并连接到中的 SQL Server。Open SQL Server Management Studio (SSMS) and connect to your SQL Server in.
右键单击 对象资源管理器 > 还原数据库 ... "中的" 数据库 "以启动 还原数据库 向导。Right-click Databases in Object Explorer > Restore Database... to launch the Restore Database wizard.
选择 " 设备 ",然后选择省略号 ( ... ) 选择一个设备。Select Device and then select the ellipses (...) to choose a device.
选择 " 添加 ",然后选择 .bak 最近移动到此位置的文件。Select Add and then choose the .bak file you recently moved to this location. 如果你将文件移到此位置但无法在向导中看到它,则这通常表示权限问题 SQL Server 或登录 SQL Server 的用户无权在此文件夹中使用此文件。If you moved your file to this location but you're not able to see it in the wizard, this typically indicates a permissions issue - SQL Server or the user signed into SQL Server does not have permission to this file in this folder.
选择 "确定" 以确认您的数据库备份选择,并关闭 " 选择备份设备 " 窗口。Select OK to confirm your database backup selection and close the Select backup devices window.
检查 " 文件 " 选项卡以确认 还原为 "位置",文件名与 " 还原数据库 向导" 中的预期位置和文件名匹配。Check the Files tab to confirm the Restore as location and file names match your intended location and file names in the Restore Database wizard.
选择“确定”以还原数据库。Select OK to restore your database.
有关还原 SQL Server 数据库的详细信息,请参阅 使用 SSMS 还原数据库备份。For more information on restoring a SQL Server database, see Restore a database backup using SSMS.
您可以使用 Transact-sql (T-sql) 还原示例数据库。You can restore your sample database using Transact-SQL (T-SQL). 下面提供了还原 AdventureWorks2019 的示例,但数据库名称和安装文件路径可能因环境而异。An example to restore AdventureWorks2019 is provided below, but the database name and installation file path may vary depending on your environment.
若要将 AdventureWorks2019 还原到 Windows,请根据环境修改相应的值,然后运行以下 Transact-sql (t-sql) 命令:To restore AdventureWorks2019 to Windows, modify values as appropriate to your environment and then run the following Transact-SQL (T-SQL) command:
USE [master]
RESTORE DATABASE [AdventureWorks2019]
FROM DISK = N'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup\AdventureWorks2019.bak'
WITH FILE = 1, NOUNLOAD, STATS = 5
GO
若要将 AdventureWorks2019 还原到 linux,请将 Windows filesystem 路径更改为 linux,然后运行以下 Transact-sql (t-sql) 命令:To restore AdventureWorks2019 to Linux, change the Windows filesystem path to Linux, and then run the following Transact-SQL (T-SQL) command:
USE [master]
RESTORE DATABASE [AdventureWorks2019]
FROM DISK = '/var/opt/mssql/backup/AdventureWorks2019.bak'
WITH MOVE 'AdventureWorks2017' TO '/var/opt/mssql/data/AdventureWorks2019.mdf',
MOVE 'AdventureWorks2017_log' TO '/var/opt/mssql/data/AdventureWorks2019_log.ldf',
FILE = 1, NOUNLOAD, STATS = 5
GO
若要在 Azure Data Studio 中还原数据库,请执行以下步骤:To restore your database in Azure Data Studio, follow these steps:
.bak从 "下载备份文件" 部分中提供的链接之一下载相应的文件。Download the appropriate .bak file from one of links provided in the download backup files section.
将该 .bak 文件移动到 SQL Server 的备份位置。Move the .bak file to your SQL Server backup location. 这不同于安装位置、实例名称和 SQL Server 版本。This varies depending on your installation location, instance name and version of SQL Server. 例如,SQL Server 2019 的默认实例的默认位置是:For example, the default location for a default instance of SQL Server 2019 is:
C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup.C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\Backup.
打开 Azure Data Studio Studio 并连接到 SQL Server 实例。Open Azure Data Studio Studio and connect to your SQL Server instance.
右键单击服务器,然后选择 " 管理"。Right-click on your server and select Manage.
选择 还原Select Restore
在 " 常规 " 选项卡上,填写 " 源" 下列出的值。On the General tab, fill in the values listed under Source.
在 " 还原自" 下,选择 " 备份文件"。Under Restore from, select Backup file.
在 " 备份文件路径" 下,选择存储 .bak 文件的位置。Under Backup file path, select the location you stored the .bak file.
这会自动填充其他字段,例如 数据库、 目标数据库 和 还原到。This auto-populates the rest of the fields such as Database, Target database and Restore to.
选择 " 还原 " 以还原数据库。Select Restore to restore your database.
部署到 Azure SQL 数据库Deploy to Azure SQL Database
可以通过两个选项查看示例 Azure SQL 数据库数据。You have two options to view sample Azure SQL Database data. 创建新数据库时,可以使用示例,或者可以使用 SQL Server Management Studio (SSMS) 将数据库从 SQL Server 直接部署到 Azure。You can use a sample when you create a new database, or you can deploy a database from SQL Server directly to Azure using SQL Server Management Studio (SSMS).
若要获取 Azure SQL 托管实例的示例数据,请参阅 将全球范围内的导入程序还原到 SQL 托管实例。To get sample data for Azure SQL Managed Instance instead, see restore World Wide Importers to SQL Managed Instance.
部署新的示例数据库Deploy new sample database
在 Azure SQL 数据库中创建新数据库时,可以选择创建空白数据库,也可以选择创建示例数据库。When you create a new database in Azure SQL Database, you have the option to create a blank database, or a sample database.
请按照以下步骤使用示例数据库创建新数据库:Follow these steps to use a sample database to create a new database:
连接到 Azure 门户。Connect to your Azure portal.
选择导航窗格左上角的 " 创建资源 "。Select Create a resource in the top left of the navigation pane.
选择 " 数据库 ",然后选择 " SQL 数据库"。Select Databases and then select SQL Database.
填写所需信息以创建数据库。Fill in the requested information to create your database.
在 " 其他设置 " 选项卡上,选择 " 示例 " 作为 " 数据源" 下的现有数据:On the Additional settings tab, choose Sample as the existing data under Data source:
选择 " 创建 " 以创建新的 SQL 数据库,这是 AdventureWorksLT 数据库的还原副本。Select Create to create your new SQL Database, which is the restored copy of the AdventureWorksLT database.
从 SQL Server 部署数据库Deploy database from SQL Server
SQL Server Management Studio 提供直接将数据库部署到 Azure SQL 数据库的功能。SQL Server Management Studio provides the ability to deploy a database directly to Azure SQL Database. 此方法当前不提供数据验证,因此用于开发和测试,不应用于生产。This method does not currently provide data validation so is intended for development and testing and should not be used for production.
若要将示例数据库从 SQL Server 部署到 Azure SQL 数据库,请执行以下步骤:To deploy a sample database from SQL Server to Azure SQL Database, follow these steps:
连接到 SQL Server Management Studio 中的 SQL Server。Connect to your SQL Server in SQL Server Management Studio.
右键单击还原的数据库 对象资源管理器 > 任务" > 将数据库部署到 Microsoft Azure SQL 数据库 ..."。Right-click your restored database in Object Explorer > Tasks > Deploy Database to Microsoft Azure SQL Database....
按照向导连接到 Azure SQL 数据库并部署数据库。Follow the wizard to connect to Azure SQL Database and deploy your database.
创建脚本Creation scripts
无需还原数据库,您也可以使用脚本来创建 AdventureWorks 数据库,而无需考虑版本。Instead of restoring a database, alternatively, you can use scripts to create the AdventureWorks databases regardless of version.
以下脚本可用于创建整个 AdventureWorks 数据库:The below scripts can be used to create the entire AdventureWorks database:
有关使用脚本的其他信息可在 GitHub上找到。Additional information about using the scripts can be found on GitHub.
后续步骤Next steps
恢复示例数据库后,请使用以下教程来开始使用 SQL Server:Once you've restored your sample database, using the following tutorials to get started with SQL Server: