In this article, I’m going to introduce the data-tier applications in SQL Server. As the official documentation from Microsoft says – “Data-tier applications in SQL Server are a logical entity that can be used to develop and manage most of the SQL Server objects like tables, views, stored procedures, functions etc. as a self-contained package“. Essentially, what that means is it is a component of SQL Server, using which we can develop, build, test and deploy databases for SQL Server just like we can do for any other web or desktop applications.

在本文中,我将介绍SQL Server中的数据层应用程序。 正如Microsoft的官方文档所述–“ SQL Server中的数据层应用程序是一个逻辑实体,可以作为独立的设备用于开发和管理大多数SQL Server对象,例如表,视图,存储过程,函数等。包装 ”。 从本质上讲,这意味着它是SQL Server的组件,使用它我们可以像为其他任何Web或桌面应用程序一样为SQL Server开发,构建,测试和部署数据库。

Data-tier applications in SQL Server were initially released around a decade back with SQL Server 2008 R2. The build of a data-tier application is a DACPAC file – Data-tier AppliCation PACkage, also known as a DAC file in short. A DAC is just another compressed zip folder that contains the model of the database that is being designed in XML format along with some other files necessary for the deployment. Using a DAC, developers can develop DDL scripts for each object in the database and these scripts will be built into a DAC file, which can later be used as a deployment utility to publish the databases to various SQL Server environments. This approach of deploying SQL Server databases has reduced the hassle of managing multiple migration scripts which in other cases the developers need to maintain for each version.

SQL Server中的数据层应用程序最初是在十年前与SQL Server 2008 R2一起发布的。 一个数据层应用程序的生成是一个DACPAC文件- 数据层 PPLIÇ通货膨胀PAC卡格,也被称为在一个短DAC文件。 DAC只是另一个压缩的zip文件夹,其中包含以XML格式设计的数据库模型以及部署所需的一些其他文件。 使用DAC,开发人员可以为数据库中的每个对象开发DDL脚本,并且这些脚本将内置到DAC文件中,该文件以后可用作部署实用程序,以将数据库发布到各种SQL Server环境。 这种部署SQL Server数据库的方法减少了管理多个迁移脚本的麻烦,在其他情况下,开发人员需要为每个版本维护。

在SQL Server Management Studio(SSMS)中创建数据层应用程序 (Create data-tier applications in SQL Server Management Studio (SSMS))

Developers and Database Administrators (DBAs) can easily create DACs using SQL Server Management Studio. This enables the users to extract the DAC file from an existing database and then perform other essential operations supported by the data-tier applications. You can follow the steps below in order to extract a data-tier application.

开发人员和数据库管理员(DBA)可以使用SQL Server Management Studio轻松创建DAC。 这使用户能够从现有数据库中提取DAC文件,然后执行数据层应用程序支持的其他基本操作。 您可以按照以下步骤操作,以提取数据层应用程序。

Right-click on the existing database for which you would like to create a data-tier application. Select Tasks and then select Extract Data-tier Application...

右键单击要为其创建数据层应用程序的现有数据库。 选择“ 任务” ,然后选择“ 提取数据层应用程序”

Figure 1 – Extract Data-tier Application in SQL Server Management Studio

图1 –在SQL Server Management Studio中提取数据层应用程序

The Extract Data-Tier Application page appears. Since this wizard will generate a DAC file, we will need to provide an application name which is basically the name of the DAC file that is going to be created and an optional description along with it.

出现“提取数据层应用程序”页面。 由于此向导将生成一个DAC文件,因此我们需要提供一个应用程序名称,该名称基本上是将要创建的DAC文件的名称以及一个可选的描述

Another important point to note here is that while extracting the data-tier applications in SQL Server, we can assign a version number for the DAC file. This helps us to maintain a version history of all the DAC files that we are going to create later. Finally, specify the location where are you going to create the DAC file. In this case, I’m going to store the DAC file under this directory – “C:\temp\WideWorldImportersDW.dacpac“. Click on Next once done.

这里要注意的另一个重要点是,在SQL Server中提取数据层应用程序时,我们可以为DAC文件分配版本号 。 这有助于我们维护以后要创建的所有DAC文件的版本历史记录。 最后,指定要在其中创建DAC文件的位置。 在这种情况下,我将DAC文件存储在此目录下-“ C:\ temp \ WideWorldImportersDW.dacpac ”。 完成后单击“ 下一步”

Figure 2 – Extract Data-tier Application Wizard

图2 –提取数据层应用程序向导

Click on Next in the following pages and finally click on Finish. The data-tier application will be generated in the path that you have specified earlier.

接下来的页面中单击下一步 ,最后单击完成 。 数据层应用程序将在您之前指定的路径中生成。

Figure 3 – Building the Data-tier Application

图3 –构建数据层应用程序

Now, that the data-tier application has been created, let’s go ahead and see the contents within the DAC file.

现在,已经创建了数据层应用程序,让我们继续看一下DAC文件中的内容。

Figure 4 – DAC File Generated

图4 –生成的DAC文件

The DAC file is a simple compressed zip archive which can be opened by any zip extractor. Rename the extension of the DAC file from DACPAC to ZIP and extract the contents to the folder.

DAC文件是一个简单的压缩zip存档,可以由任何zip提取程序打开。 将DAC文件的扩展名从DACPAC重命名为ZIP ,并将内容提取到该文件夹​​中。

Figure 5 – Extract ZIP Archive

图5 –解压缩ZIP存档

Once you extract the contents of the DACPAC file, you’ll see there are four different XML files within it.

提取DACPAC文件的内容后,您将看到其中包含四个不同的XML文件。

Figure 6 – DACPAC Contents

图6 – DACPAC目录

These XML files do not contain any data from the database. The database is scripted out only with the model information. In order to also export data, there is another file which the data-tier application supports, known as BACPAC. This is essentially, a backup along with the DACPAC file that is generated.

这些XML文件不包含来自数据库的任何数据。 仅使用模型信息来编写数据库脚本。 为了也导出数据,数据层应用程序支持另一个文件,称为BACPAC。 本质上,这是一个备份以及生成的DACPAC文件。

在SQL Server Management Studio中创建BACPAC文件 (Creating a BACPAC file in SQL Server Management Studio)

The steps to create a BACPAC file is almost similar to that of creating a DACPAC. Instead of choosing Extract Data-Tier Application, in this case, you need to select the Export Data-tier Application.

创建BACPAC文件的步骤几乎与创建DACPAC的步骤相似。 在这种情况下,您无需选择“ 提取数据层应用程序” ,而是选择“ 导出数据层应用程序”

Figure 7 – Export Data-tier Application in SQL Server Management Studio

图7 –在SQL Server Management Studio中导出数据层应用程序

Proceed to the Export Settings page by clicking on Next. On this page, you can see there are two tabs – Settings and Advanced. Here, you can specify where would you like the BACPAC file to be created. You also have an option on this page to save the BACPAC file directly to Microsoft Azure instead. In this case, I’m going to save it on my local directory itself.

单击“ 下一步 进入“ 导出设置”页面。 在此页面上,您可以看到两个选项卡- 设置高级 。 在这里,您可以指定要在何处创建BACPAC文件。 您也可以在此页面上选择将BACPAC文件直接保存到Microsoft Azure。 在这种情况下,我将其保存在本地目录中。

Figure 8 – Export Data-tier Application Settings

图8 –导出数据层应用程序设置

On the same page, there’s also a second tab – Advanced. This allows us to choose from a list table under all the schemas available in the database that we are trying to export. You can choose the tables for which the data needs to be generated in the BACPAC file. Let’s select all the tables for this example and click on Next and finally click on Finish.

在同一页面上,还有另一个选项卡– Advanced 。 这使我们可以从列表表中选择要导出的数据库中所有可用模式下的列表。 您可以在BACPAC文件中选择需要为其生成数据的表。 让我们选择该示例的所有表,然后单击Next ,最后单击Finish

Figure 9 – Export Data-tier Application Advanced Setting

图9 –导出数据层应用程序高级设置

The operation might take a while based on the size of the data that is being exported. You can see a list of all the tables that have been exported in the BACPAC file. Once the operation is completed successfully, click Close.

该操作可能需要一些时间,具体取决于要导出的数据的大小。 您可以在BACPAC文件中看到所有已导出表的列表。 操作成功完成后,点击关闭

Figure 10 – Export BACPAC Operation

图10 –导出BACPAC操作

Like the DACPAC file, the BACPAC file is also a compressed zip archive which can be renamed into a ZIP extension and we can view the contents within. I have renamed the extension of the file to zip and extracted the contents.

像DACPAC文件一样,BACPAC文件也是压缩的zip存档,可以将其重命名为ZIP扩展名,我们可以查看其中的内容。 我已将文件扩展名重命名为zip并提取了内容。

Figure 11 – BACPAC File Contents

图11 – BACPAC文件内容

As you can see in the figure above, in addition to the contents of the DACPAC file, we have two new directories in this – “_rels” and “Data“. In the Data directory, you can see a directory has been created for all the tables that you’ve selected while exporting the BACPAC file.

如上图所示,除了DACPAC文件的内容之外,我们在其中还有两个新目录-_relsData 。 在“ 数据”目录中,您可以看到在导出BACPAC文件时为所有选择的表创建了目录。

Figure 12 – BACPAC Data Directories

图12 – BACPAC数据目录

Also, if you open further, each of these data directories contains a BCP file for that table, which is essentially the BCP utility in the SQL Server to bulk copy these data back into the database when restored.

另外,如果进一步打开,则这些数据目录中的每个目录都包含该表的BCP文件,该文件实质上是SQL Server中的BCP实用程序,用于在还原时将这些数据批量复制回数据库中。

Figure 13 – BACPAC File Contents

图13 – BACPAC文件内容

在SQL Server Management Studio中导入数据层应用程序 (Importing a data-tier application in SQL Server Management Studio)

We can import the BACPAC file back to the SQL Server instance, and the database will be restored as-is on the target server. Since we can import a BACPAC file, then the data along with the schema will be restored on the server. You can follow the steps below to import a data-tier application in SQL Server.

我们可以将BACPAC文件导入回SQL Server实例,数据库将在目标服务器上按原样还原。 由于我们可以导入BACPAC文件,因此数据和模式将在服务器上恢复。 您可以按照以下步骤在SQL Server中导入数据层应用程序。

Right-click on the Databases and select “Import Data-Tier Application…” from the context menu.

右键单击数据库,然后从上下文菜单中选择“ Import Data-Tier Application… ”。

Figure 14 – Import Data-tier Applications in SQL Server

图14 –在SQL Server中导入数据层应用程序

On the next page that appears, provide the proper path of the BACPAC file and click on Next.

在出现的下一页上,提供BACPAC文件的正确路径 ,然后单击“ 下一步”

Figure 15 – BACPAC File Location

图15 – BACPAC文件位置

In the Database Settings page that appears, you can choose the name of the database and the location where the data files should be created. By default, it will take the path of the SQL Server Default Data directory. Click Next and finally on Finish once done.

在出现的“数据库设置”页面中,您可以选择数据库的名称以及应该在其中创建数据文件的位置。 默认情况下,它将采用SQL Server默认数据目录的路径。 一旦完成后,单击下一步 ,终于完成

Figure 16 – Database Settings

图16 –数据库设置

The wizard will import the data-tier application and a database will be created once the process is completed successfully.

该向导将导入数据层应用程序,一旦成功完成该过程,便会创建一个数据库。

Figure 17 – Import Completed

图17 –导入完成

结论 (Conclusion)

In this article, I have explained what data-tier applications in SQL Server are. I have also explained how to create a DACPAC and BACPAC using SQL Server Management Studio. DACPAC files are just a copy of the schema from the entire database without any data whereas, in the BACPAC file, data is included as well. In my upcoming articles for data-tier applications in SQL Server, I’ll explain how to start developing the same from scratch using Visual Studio and SQL Server Data Tools.

在本文中,我解释了SQL Server中的数据层应用程序。 我还介绍了如何使用SQL Server Management Studio创建DACPAC和BACPAC。 DACPAC文件只是整个数据库中模式的副本,没有任何数据,而在BACPAC文件中,数据也包括在内。 在我即将发表的有关SQL Server中数据层应用程序的文章中,我将说明如何使用Visual Studio和SQL Server数据工具从头开始开发相同的内容。

翻译自: https://www.sqlshack.com/an-introduction-to-data-tier-applications-in-sql-server/

SQL Server中的数据层应用程序简介相关推荐

  1. 在AWS RDS SQL Server中恢复数据

    This article explores the process to recover data in AWS RDS SQL Server and its recent enhancements. ...

  2. php删除sql server 2008,MSSQL_SQL Server2008 数据库误删除数据的恢复方法分享,SQL Server中误删除数据的恢复本 - phpStudy...

    SQL Server2008 数据库误删除数据的恢复方法分享 SQL Server中误删除数据的恢复本来不是件难事,从事务日志恢复即可.但是,这个恢复需要有两个前提条件: 1. 至少有一个误删除之前的 ...

  3. 十步优化SQL Server中的数据访问

    故事开篇:你和你的团队经过不懈努力,终于使网站成功上线,刚开始时,注册用户较少,网站性能表现不错,但随着注册用户的增多,访问速度开始变慢,一些用户开始发来邮件表示抗议,事情变得越来越糟,为了留住用户, ...

  4. (转)SQLServer_十步优化SQL Server中的数据访问 三

    原文地址:http://tech.it168.com/a2009/1125/814/000000814758_all.shtml 第六步:应用高级索引 实施计算列并在这些列上创建索引 你可能曾经写过从 ...

  5. 如何在SQL Server中使用数据质量服务清除主数据服务数据

    介绍 (Introduction) A few weeks back, I was approached by a client who lives in Cape Town, South Afric ...

  6. 如何将Sql Server中的数据表导入到PowerDesigner中

    本文主要介绍一下基本工作 如何将在SQL Server中设计好的数据表结构导入到PowerDesigner中. 我采用的是SQL Server 2005跟PowerDesigner15.1版本,首先打 ...

  7. 使用命令行导出 SQL Server 数据层应用程序

    点击上方蓝字关注"汪宇杰博客" 我们可以使用 SSMS 导出 SQL Server 数据库的数据层应用程序.我在本地机器上使用这种方法已经有好几年了.如果不知道什么是 DAC,您可 ...

  8. java代码转置sql数据_SQL Server中的数据科学:数据分析和转换–使用SQL透视和转置

    java代码转置sql数据 In data science, understanding and preparing data is critical, such as the use of the ...

  9. sql数据透视_SQL Server中的数据科学:取消数据透视

    sql数据透视 In this article, in the series, we'll discuss understanding and preparing data by using SQL ...

最新文章

  1. 旷视科技完成4.6亿美元C轮融资,打破商汤4.1亿美元单轮融资记录
  2. 供应链金融服务平台:应收、预付和存货融资业务
  3. 请求接口获取到的数据其中出现null值,处理的时候导致了程序crash,解决方案如下:...
  4. node静态服务器优缺点_使用 Node.js 的优势和劣势都有哪些?
  5. Tipard Video Converter Ultimate如何旋转视频?
  6. 免费json客户端解析
  7. UI设计图标素材|如何应用合适图标
  8. c++语言socket udp聊天程序,使用C/C++实现Socket聊天程序
  9. vscode 运行 python
  10. 【Axure RP8.1】一款专业的快速原型设计工具
  11. 计算机主机的组成部分,计算机主机的组成是有哪些
  12. open drain和push pull
  13. Dubbo-接口数据序列化Serialization
  14. 神仙科研夫妇!浙大博士夫妻赴耶鲁深造,如今归国任教985
  15. C 语言有哪些优点?
  16. Linux必学的60个命令(文字整理版)
  17. 计算机数制转换操作方法,计算机基础 数制及其相互转换
  18. 学生信息管理系统-教师端
  19. 如何配置域名的 CNAME
  20. FAERIE QVEENE 仙后节选

热门文章

  1. 不花钱的pdf编辑器_真香!免费pdf处理工具,等你来拿。工作又轻松了一步
  2. R 回归 虚拟变量na_互助问答第85期:虚拟变量和空间面板回归问题
  3. centos7 安装pip
  4. JS对象 字符串分割 split() 方法将字符串分割为字符串数组,并返回此数组。 语法: stringObject.split(separator,limit)...
  5. extracting lines bases a list using awk
  6. mongoose数据查询or、and、where等用法
  7. 【零基础学Java】—TCP通信(五十四)
  8. 2引擎帮助文档_ANSA快速入门指南中文帮助文档浅析(上)
  9. 手机的余存电量还有多少的时候适合充电?
  10. erp系统是什么转型