如何:创建项目的快照How to: Create a Snapshot of a Project

数据层应用程序文件为你在创建数据库架构时提供数据库架构的只读表示形式。A Data-tier Application file provides you with a read-only representation of the database schema at the time it is created. 该文件实质上被视为可以将其中的架构对象导入回某一项目的一种数据库架构。It is essentially being treated as a database schema from which you can import the schema objects back to a project. 您还可以将其与某一数据库或项目的架构进行比较,并且更新该数据库或项目以便反映在该快照中定义的架构。You can also compare it with the schema of a database or a project, and update the database or project to reflect the schema defined in the snapshot.

如果某一源数据库项目出现用户错误,还可将该源项目恢复到创建快照时的状态。In the event of a user error on a source database project, you can revert the source project to the state it was in when the snapshot was created. 您也可以在不同的开发阶段中出于基准目的建立快照。You can also establish snapshots at various stages of your development for baseline purpose.

警告

以下过程利用在连接的数据库开发面向项目的脱机数据库开发部分中的之前过程中创建的实体。The following procedures utilize entities created in previous procedures in the Connected Database Development and Project-Oriented Offline Database Development sections.

要创建快照,请执行以下操作To create a snapshot

  1. 在“解决方案资源管理器”中,右键单击“TradeDev”项目,然后选择“数据层应用程序(*.dacpac)…”。Right-click the TradeDev project in Solution Explorer, and select Data-tier Application (*.dacpac)....

  2. SSDT 将首先尝试生成该项目。SSDT will attempt to build the project first. 如果没有生成错误,则在“解决方案资源管理器”中创建一个“快照”文件夹。If there is no build error, a Snapshot folder is created in Solution Explorer. 在此文件夹中,SSDT 将使用“_YYYYMMDD_HH-MM-SS.dacpac”的名称格式创建一个 .dacpac 文件。Inside this folder, SSDT creates a .dacpac file using the name format of "_YYYYMMDD_HH-MM-SS.dacpac".

  3. 右键单击 .dacpac 文件,然后选择“重命名”。Right-click the .dacpac file and select Rename. 将该默认文件名更改为“TradeDev1.dacpac”。Change the default file name to "TradeDev1.dacpac".

  4. 在“解决方案资源管理器”中右键单击 GetProductsBySupplier 函数,然后选择“删除”以便从项目中删除它。Right-click the GetProductsBySupplier function in Solution Explorer and select Delete to remove it from the project.

  5. 按照前面的步骤,创建名为 TradeDev2.dacpac 的一个新快照。Follow the previous steps to create a new snapshot called TradeDev2.dacpac.

导入快照To import a snapshot

  1. 在“解决方案资源管理器”中,右键单击“TradeDev”项目,选择“导入”,然后从上下文菜单中选择“数据层应用程序(*.dacpac)…”。Right-click the TradeDev project in Solution Explorer, select Import, then Data-tier Application (*.dacpac)... from the contextual menus.

  2. 在“导入数据层应用程序”对话框中,单击“浏览”以便选择要用作导入的源的 TradeDev1.dacpac。In the Import Data-tier Application dialog box, click Browse to select TradeDev1.dacpac to be used as the source of the import.

    请注意,“目标项目”部分已被禁用,因为当前项目是默认目标。Notice that the Target project section has been disabled, since the current project is the default target. 单击“启动”以开始导入。Click Start to start the import.

  3. 在“摘要”页中单击“完成”。Click Finish in the Summary page. 在“解决方案资源管理器”中,请注意删除的表已还原到该项目。In Solution Explorer, notice that the deleted table has been restored to the project.

    警告

    导入快照将快照架构中的所有数据库实体都导入到项目中。The import snapshot will import all database entities in the snapshot schema to the project. 因此这可以创建重复的实体。This might create duplicate entities as a result. 例如,每个表和视图现在都包含一个名为 <ObjectName_1> 的自身的另外一个副本。For example, each of the tables and view now contains an additional copy of itself named <ObjectName_1>. 在“解决方案资源管理器”中右键单击上述各重复对象,然后选择“删除”以便从项目中删除它。Right-click each of these duplicate objects in Solution Explorer and select Delete to remove it from the project.

比较快照To compare snapshots

  1. 在“解决方案资源管理器”中右键单击 TradeDev1.dacpac,然后选择“架构比较”。Right-click TradeDev1.dacpac in Solution Explorer and select Schema Compare. 将打开“架构比较”窗口。The Schema Compare window opens.

  2. 使用“数据层应用程序文件”选项来设置源和目标架构。Use the Data-tier Application File options to set the source and target schemas. 请确保“源架构”在“数据层应用程序文件”中设置为 TradeDev1.dacpac,“目标架构”设置为 TradeDev2.dacpac。Make sure that the Source Schema is set to TradeDev1.dacpac in Data-tier Application File, and the Target Schema is set to TradeDev2.dacpac.

  3. 单击“确定”以开始比较。Click OK to start the compare. 请注意,删除的函数将作为旧快照和新快照之间的差异而被突出显示。Notice that the deleted function is being highlighted as a difference between the old and new snapshot.

    通过使用架构比较,您可以轻松找到不同快照之间的差异。You can easily find the delta of different snapshots by using Schema Compare. 在本例中,您可以了解在开发过程中您的项目的发展情况。In this case, you can find out how your project evolves during the development process.

另请参阅See Also

如何:使用架构比较来比较不同数据库定义How to: Use Schema Compare to Compare Different Database Definitions