安装和配置AdventureWorks2016示例数据库

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.

本文介绍了在SQL Server和Azure SQL Server的独立实例上安装AdventureWorks2016和AdventureWorksDW2016示例数据库的过程。 样本数据库由Microsoft发布,以演示如何使用SQL Server设计数据库。 Microsoft还发布了另一个名为AdventureworksLT的轻量级数据库该数据库可用作Azure SQL Server上的示例数据库。

在独立SQL实例上安装示例数据库 (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.

要安装AdventureWorks2016AdventureWorksDW2016数据库,必须安装SQL Server Express / Standard / Enterprise Edition和SQL Server Management Studio。

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

在独立SQL实例上,可以通过以下方法安装两个数据库:

  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

    从GitHub下载安装脚本并通过执行脚本来构建数据库

使用完整备份安装Adventureworks2016 (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:

首先,让我们使用备份文件安装数据库。 您可以从以下链接下载AdventureWorks示例数据库:

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:

下载备份后,打开SQL Server Management Studio,然后从Object Explorer中展开数据库引擎,右键单击Databases并选择Restore Database 。 见下图:

安装和配置AdventureWorks2016示例数据库

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

在“ 还原数据库”窗口中,选择“ 设备”作为源,然后单击“椭圆”(…):

安装和配置AdventureWorks2016示例数据库

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:

在“ 找到备份设备”窗口中,单击“ 添加”选择备份媒体,然后在新打开的窗口中导航到下载数据库备份的目录,然后选择备份(.bak)文件。 点击确定

安装和配置AdventureWorks2016示例数据库

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:

如果要更改数据文件和日志文件的物理位置,请单击“ 文件”窗格,然后更改数据和日志文件的目标位置。 请注意,最佳做法是将数据文件和日志文件保存在单独的驱动器上:

安装和配置AdventureWorks2016示例数据库

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:

单击确定 。 它将启动数据库还原过程。 数据库成功还原后,将显示一个弹出窗口,说明数据库已成功还原。 见下图:

安装和配置AdventureWorks2016示例数据库

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

现在,我们的数据库已还原,我们可以使用SQL Server Management Studio进行连接。 见下图:

安装和配置AdventureWorks2016示例数据库

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

同样,您可以从下面的链接下载AdventureWorksDW2016并通过在SQL Server独立实例上还原数据库来进行安装。

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

您可以从以下链接下载AdventureWorks数据仓库数据库:

通过执行安装脚本来构建数据库 (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.

我们还可以通过在SQL Server上执行数据库安装脚本来准备数据库。 为此,首先,必须下载AdventureWorks2016AdventureWorksDW2016数据库的安装脚本。 您可以从AdventureWorks-OLTP-install-script.zip下载AdventureWorks OLTP数据库的安装脚本,也可以使用OLTP-install-script GitHub文件夹中的文件。

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

下载文件后,请使用WinRar或任何其他数据压缩工具提取这些文件。 解压缩文件后,执行以下步骤:

  1. Enable the SQL Server full-text search feature

    启用S​​QL Server全文搜索功能
  2. Copy the installation script and other files to “C:\AWorks2016Database\” directory

    将安装脚本和其他文件复制到“ C:\ AWorks2016Database \ ”目录中
  3. Open the “instawdb.sql” file in SQL Server Management Studio

    在SQL Server Management Studio中打开“ instawdb.sql ”文件
  4. Change the value of the environment variable SqlSamplesSourceDataPath to “C:\AWorks2016Database\

    :setvar SqlSamplesSourceDataPath “C:\AWorks2016Database\”

    将环境变量SqlSamplesSourceDataPath的值更改为“ C:\ AWorks2016Database \

    :setvar SqlSamplesSourceDataPath“ C:\ AWorks2016Database \”

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

    :setvar DatabaseName “AdventureWorks2016_InstallScript

    将环境变量DatabaseName的值更改为“ 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:

    安装和配置AdventureWorks2016示例数据库

    要执行脚本,我们必须在SSMS中启用SQLCMD模式。 为此,请单击“ 查询”菜单,然后选择“ SQLCMD模式” 。 见下图:

  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

    安装和配置AdventureWorks2016示例数据库

    单击执行或按F5运行脚本

    该脚本将创建所有数据库对象并将其添加到表中

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:

脚本成功执行后,您可以在SQL Server Management Studio的对象资源管理器中看到AdventureWorks2016_InstallScript数据库。 见下图:

安装和配置AdventureWorks2016示例数据库

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.

同样,要安装AdventureWorksDW2016 ,必须下载安装脚本。 您可以从AdventureWorksDW-data-warehouse-install-script.zip下载AdventureWorks OLAP数据库的安装脚本,也可以使用data-warehouse-install-script Github文件夹中的文件。 要安装AdventureWorksDW2016数据库,请遵循我上面解释的相同过程。

在Azure SQL Server上安装示例数据库 (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:

若要在Azure SQL Server上安装示例数据库,必须使用AdventureWorksLT数据库创建一个SQL Server资源组。 为此,登录到Microsoft Azure门户,然后在主屏幕上,单击创建资源 。 见下图:

安装和配置AdventureWorks2016示例数据库

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

在下一个屏幕上,单击SQL数据库 。 见下图:

安装和配置AdventureWorks2016示例数据库

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:

在下一个屏幕上,填写预订,资源组,数据库名称,服务器名称以及计算+存储类型的详细信息。 单击下一步 。 见下图:

安装和配置AdventureWorks2016示例数据库

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:

在“ 其他设置”菜单中,从“ 数据源”部分下的“ 使用现有数据”选项中选择“ 样本” 。 单击审阅+创建 。 见下图:

安装和配置AdventureWorks2016示例数据库

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

Review + create步骤中,验证配置,然后单击Create

安装和配置AdventureWorks2016示例数据库

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:

SQL数据库部署过程将开始。 这将需要几分钟。 部署过程完成后,您将能够从SQL Server Management Studio连接到数据库。 见下图:

安装和配置AdventureWorks2016示例数据库

摘要 (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.

在本文中,我解释了如何使用完整的备份和安装脚本在SQL Server独立实例上安装AdventureWorks2016示例数据库。 此外,我还在Azure SQL Server上安装了AdventureWorksLT数据库。

翻译自: https://www.sqlshack.com/install-and-configure-the-adventureworks2016-sample-database/