The control table
One row per source table: what to copy, by which column changes are found, and how far the last run got.
A pipeline per table works for three tables. At thirty, every change to the way you copy has to be made thirty times, and a new table means a new pipeline. A control table turns that around: the pipeline stays the same, and the list of what to copy lives in a table you can read, change and query.
What goes in it
One row per source table, with what the pipeline needs to know about it:
- SchemaName and TableName: which table to copy.
- WatermarkColumn: the column that shows a row changed, usually a modified date. Lesson 3 uses it.
- LastWatermark: how far the last successful run got.
- IsActive: switch a table off without deleting its row.
- LastRunAt and LastRunStatus: what happened the last time, for you and for monitoring.
Create it
Run this in the Azure SQL Database the pipeline will read from (the query editor in the Azure portal works). The etl schema keeps the pipeline's own tables apart from the business data.
CREATE SCHEMA etl;
GO
CREATE TABLE etl.LoadControl (
SchemaName sysname NOT NULL,
TableName sysname NOT NULL,
WatermarkColumn sysname NOT NULL,
LastWatermark datetime2 NOT NULL DEFAULT '1900-01-01',
IsActive bit NOT NULL DEFAULT 1,
LastRunAt datetime2 NULL,
LastRunStatus nvarchar(20) NULL,
CONSTRAINT PK_LoadControl PRIMARY KEY (SchemaName, TableName)
);Fill it
With the AdventureWorksLT sample, three tables are enough to see it work. Each of them has a ModifiedDate column.
INSERT INTO etl.LoadControl (SchemaName, TableName, WatermarkColumn)
VALUES ('SalesLT', 'Customer', 'ModifiedDate'),
('SalesLT', 'Product', 'ModifiedDate'),
('SalesLT', 'SalesOrderHeader', 'ModifiedDate');The watermark starts at 1 January 1900, so the first run copies everything. That is the full load; every run after it is incremental.
Check it
SELECT SchemaName, TableName, WatermarkColumn, LastWatermark
FROM etl.LoadControl
WHERE IsActive = 1;This query is the one the pipeline runs first, in the next lesson. Three rows back means three tables to copy.