在 Azure SQL Edge 中跟踪数据更改Track data changes in Azure SQL Edge

Azure SQL Edge 支持两个 SQL Server 功能,这些功能可跟踪数据库中的数据更改:更改跟踪变更数据捕获Azure SQL Edge supports the two SQL Server features that track changes to data in a database: change tracking and change data capture. 这两个功能使应用程序能够确定对数据库中的用户表所做的数据修改语言更改(插入、更新和删除操作)。These features enable applications to determine the data modification language changes (insert, update, and delete operations) that were made to user tables in a database. 可以对同一数据库启用变更数据捕获和更改跟踪。You can enable change data capture and change tracking on the same database. 没有特殊的注意事项。No special considerations are required.

对于某些注重效能的应用程序来说,查询数据库中已更改的数据的能力是一项很重要的要求。The ability to query for data that has changed in a database is an important requirement for some applications to be efficient. 通常,为了确定数据更改,应用程序开发人员必须在其应用程序中使用触发器、时间戳列和其他表的组合来实现自定义跟踪方法。Typically, to determine data changes, application developers must implement a custom tracking method in their applications by using a combination of triggers, timestamp columns, and additional tables. 创建这些应用程序通常涉及多项工作,导致架构更新,并且通常带来较高的性能开销。Creating these applications usually involves a lot of work to implement, leads to schema updates, and often carries a high performance overhead.

对于需要定期将数据从边缘移动到云或数据中心的 IoT 解决方案,更改跟踪可能非常有用。In the case of an IoT solution, where you need to periodically move data from the edge to a cloud or datacenter, change tracking can be very useful. 用户可以快速有效地查询自上次同步以来的更改,并将这些更改上传到云或数据中心目标。Users can quickly and effectively query only the changes from the last sync, and upload those changes to the cloud or datacenter target. 有关更多详细信息,请参阅使用变更数据捕获或更改跟踪的优势For additional details, see Benefits of using change data capture or change tracking.

这两种功能并不相同。These two features aren't the same. 有关详细信息,请参阅变更数据捕获与更改跟踪之间的功能差异For more information, see Feature differences between change data capture and change tracking

更改数据捕获Change data capture

要详细了解此功能的工作原理,请参阅关于变更数据捕获To understand the details of how this feature works, see About change data capture.

要了解如何启用或禁用此功能,请参阅启用和禁用变更数据捕获To understand how to enable or disable this feature, see Enable and disable change data capture.

要管理和监视此功能,请参阅管理和监视变更数据捕获To administer and monitor this feature, see Administer and monitor change data capture.

要了解如何查询和处理更改后的数据,请参阅处理变更数据To understand how to query and work with the changed data, see Work with change data.

Change trackingChange tracking

要详细了解此功能的工作原理,请参阅关于更改跟踪To understand the details of how this feature works, see About change tracking.

要了解如何启用或禁用此功能,请参阅启用和禁用更改跟踪To understand how to enable or disable this feature, see Enable and disable change tracking.

要管理、监视和管理此功能,请参阅管理和监视更改跟踪To administer, monitor, and manage this feature, see Administer and monitor change tracking.

要了解如何查询和处理更改后的数据,请参阅处理变更数据To understand how to query and work with the changed data, see Work with change data.

临时表Temporal tables

Azure SQL Edge 还支持 SQL Server 的临时表功能。Azure SQL Edge also supports the temporal tables feature of SQL Server. 此功能(由系统控制版本的临时表)引入了内置支持,可以提供表中存储的数据在任意时间点的相关信息。This feature (also known as system-versioned temporal tables) brings built-in support for providing information about data stored in the table at any point in time. 此功能不仅仅提供在当前时刻正确的数据的相关信息。The feature doesn't simply provide information about only the data that is correct at the current moment in time.

版本由系统控制的临时表是用户表的一种类型,旨在保留完整的数据更改历史记录,并实现轻松的时间点分析。A system-versioned temporal table is a type of user table designed to keep a full history of data changes, and to allow easy point-in-time analysis. 这种类型的临时表之所以称为版本由系统控制的临时表,是因为每一行的有效期由系统(即数据库引擎)管理。This type of temporal table is referred to as a system-versioned temporal table because the period of validity for each row is managed by the system (that is, the database engine).

每个临时表有两个显式定义的列,其中每个列都有一个 datetime2 数据类型。Every temporal table has two explicitly defined columns, each with a datetime2 data type. 这些列称为期限列。These columns are referred to as period columns. 每当修改了某行后,系统都将以独占方式使用这些期限列来记录每行的有效期。The system uses these period columns exclusively, to record the period of validity for each row whenever a row is modified.

除了这些期限列以外,临时表还包含对使用镜像架构的另一个表的引用。In addition to these period columns, a temporal table also contains a reference to another table with a mirrored schema. 每当更新或删除了临时表中的某行后,系统将使用此表来自动存储该行的先前版本。The system uses this table to automatically store the previous version of the row each time a row in the temporal table gets updated or deleted. 此附加表称为历史记录表,而存储当前(实际)行版本的主表称为当前表,或直接称为临时表 。This additional table is referred to as the history table, while the main table that stores current (actual) row versions is referred to as the current table, or simply as the temporal table. 在创建临时表期间,用户可以指定现有的历史记录表(它必须与架构相符),或者让系统创建默认的历史记录表。During temporal table creation, users can specify an existing history table (it must be compliant with the schema), or let the system create the default history table.

有关详细信息,请参阅临时表For more information, see Temporal tables.

后续步骤Next steps