Short answer: keep a control table with one row per source table, and build one parameterised pipeline: a Lookup reads the control table, a ForEach runs one Copy per row, and each copy writes its result back. Adding a table to the load is then an INSERT, not a new pipeline.
A pipeline per table is fine for three tables. At thirty, every change to how you copy (a new folder layout, a retry setting, a log line) has to be made thirty times, and every new table is a release. The metadata-driven pattern turns that around: the pipeline stays the same, and what it copies lives in a table you can read, query and change.
How does a metadata-driven pipeline work?
- 1Control tableone row per source table, with its key and its last load
- 2Lookupreads the active rows
- 3ForEachone iteration per row, several at a time
- 4Copythe table into its own folder in the lake
- 5Write backthe run's result into the control table
The pipeline never names a table. The Lookup returns a list, the ForEach walks it, and inside the loop @item() is the current row: its schema, its table name and whatever else the row holds.
What goes in the control table?
Only what the pipeline needs to decide what to copy and to report what happened:
| SchemaName | TableName | WatermarkColumn | IsActive | LastRunStatus |
|---|---|---|---|---|
| SalesLT | Customer | ModifiedDate | 1 | Succeeded |
| SalesLT | Product | ModifiedDate | 1 | Succeeded |
| SalesLT | SalesOrderHeader | ModifiedDate | 1 | Failed |
| SalesLT | ProductModel | ModifiedDate | 0 | Skipped |
IsActive switches a table off without deleting its row, and the last two columns tell you, and your monitoring, what the last run did. The struck-out row above is switched off, so the Lookup never returns it.
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)
);How do you build the pipeline?
- A Lookup activity with First row only turned off, and the query below as its source.
- A ForEach whose items are
@activity('Lookup control').output.value. Leave Sequential off and set a Batch count, so several tables copy at once. - Inside the ForEach, a Copy activity. Its source dataset takes
SchemaNameandTableNameas parameters, filled with@item().SchemaNameand@item().TableName. Its sink dataset writes to a folder built from the same values, for exampleraw/@{item().SchemaName}/@{item().TableName}/. - After the Copy, a Stored procedure activity that writes
LastRunAtandLastRunStatusback for that row. Put one on the success path and one on the failure path, so a failed table is marked failed.
The Lookup's query:
SELECT SchemaName, TableName, WatermarkColumn, LastWatermark
FROM etl.LoadControl
WHERE IsActive = 1;Two datasets (one source, one sink) serve every table. That is the whole saving: the copy logic exists once.
What are the limits?
- A Lookup returns at most 5,000 rows and 4 MB. A control table rarely gets near that, but if yours does, split it by a group column and run one ForEach per group.
- A ForEach runs up to 50 iterations at the same time (the default is 20). The source database decides the real limit: start low and raise it while you watch it.
- A ForEach cannot hold another ForEach. If each table needs its own loop, move the inner part into a second pipeline and call it with Execute Pipeline.
What goes wrong?
- One table fails, and you only find out from the pipeline's red status. The write-back step on the failure path is what tells you which table, and why. Without it you open run history and click through the iterations.
- A copy runs into a table that changed shape. A new column in the source flows into the Parquet files without complaint, but a report downstream may break. Keep schema drift visible: compare the columns the copy wrote with the columns it wrote last time.
- Every run copies everything. That is the next step: a watermark per table, so each run asks for the newer rows only. See Load only the rows that changed.
Where can you check this?
- Microsoft Learn: Lookup activity in Azure Data Factory
- Microsoft Learn: ForEach activity in Azure Data Factory
- Microsoft Learn: Build a metadata-driven copy task with the Copy Data tool
Where do you start?
The open course Your first metadata-driven pipeline builds this pattern step by step in your own Azure subscription: the control table, the Lookup, ForEach and Copy, and the watermark that makes it incremental. The pattern sits with the others on the map of my work.