Remove duplicates when persisting
On this page
Remove duplicates removes rows from the destination after loading, keeping one arbitrary row for each duplicate-detection key. It does not copy the source to a temporary table or clean source rows before loading.
Which key is used?
- If the source transformation contains the surrogate-key column named by
HIST_ID_FIELDNAME, that column alone is used. - Otherwise, the source primary-key columns are used together.
- If neither exists, the option is disabled in the editor and ignored by the generator for older configurations.
The configured name is normally SATZ_ID, but it can be changed in DWH Settings. A business key such as EmployeeID does not replace an available surrogate key. Two history versions with different surrogate keys are retained even if their business key is identical.
Where to configure it
Open the persisting definition and select Remove duplicates. Save, inspect Procedure, then regenerate and deploy the procedure using your normal deployment workflow. Changing the setting or generator does not alter an already deployed procedure automatically.
Applicable modes and operation order
| Mode | Destination cleanup |
|---|---|
| Full, direct replacement | After truncate/insert, immediately before commit. |
| Full, Partition switching or Renaming | After replacement, against the final destination, immediately before commit. |
| Merge | After MERGE, immediately before commit. |
| Historical | After history updates/inserts, immediately before commit. |
| Incremental (insert-only) | After the incremental insert, immediately before commit. |
| Incremental (insert and update-only) | After MERGE, immediately before commit. |
| Manual | User-authored SQL is preserved; no cleanup is inserted automatically. |
When Use transaction is disabled, the same statement order applies, but the generated transaction statements are commented out. Do not assume rollback protection in that configuration. Cleanup covers the destination, not just rows inserted in the current run.
The Full-mode replacement table is part of the selected loading strategy. It is not a preliminary copy introduced by Remove duplicates. Other modes read their configured source directly.
Generated SQL pattern
This illustrative fragment deletes rows from the underlying destination. Actual generated code chooses the configured key and an internal row-number alias that avoids collisions with source column names.
;WITH toDelete AS
(
SELECT [SATZ_ID],
ROW_NUMBER() OVER
(PARTITION BY [SATZ_ID] ORDER BY NEWID()) AS DuplicateNumber
FROM [DWH].[ExampleDimension]
)
DELETE FROM toDelete WHERE DuplicateNumber > 1;
-- COMMIT TRAN follows when transactions are enabled.
Deleting through the CTE is intentional: the computed row number belongs to the CTE, while the deleted records belong to its underlying table.
Expected result and limits
After successful loading and cleanup, at most one row remains per selected key. Non-key values do not determine duplication or which row survives. The option does not prefer the latest date or a particular business value.
Cleanup cannot repair a load that fails before reaching it. Conflicting source rows can cause a MERGE error or a unique-constraint violation during loading. Inspect the source and generated matching condition separately in that case. The generator's DISTINCT projections in Merge are not a general rule for choosing one row per source key.
See the worked example, mode reference and loading troubleshooting.