Launch price: every exam for $29.99 a year, for the first 300 buyers. See the price

CertStreak
Menu

Load data by using merge, insert, and append operations

A worked example

Yes or no

A data engineer runs two loading jobs against Delta tables in Unity Catalog. Default settings are used.

Job A loads product_feed into products. Both tables have the same schema. The products table contains one row for SKU P-100 with a price of 10.00. Today, product_feed contains two rows for SKU P-100: one with a price of 12.00 and one with a price of 13.00.

Job B corrects the first week of January in sales.transactions. The source, staging.corrected_transactions, contains 500 rows dated 2026-01-01 through 2026-01-07 and 3 rows dated 2026-01-08.

The exhibit shows both statements.

-- Job A MERGE INTO products AS target USING product_feed AS source ON target.sku = source.sku WHEN MATCHED AND source.price <> target.price THEN UPDATE SET target.price = source.price, target.updated_at = current_timestamp() WHEN NOT MATCHED THEN INSERT *;

-- Job B INSERT INTO sales.transactions REPLACE WHERE transaction_date >= '2026-01-01' AND transaction_date <= '2026-01-07' SELECT * FROM staging.corrected_transactions;

For each of the following statements, select Yes if the statement is true. Otherwise, select No.

StatementYesNo
Job A fails because two source rows match the same target row.

Both P-100 source rows match the single P-100 target row and both have a price that differs from 10.00, so the update clause applies to each. MERGE fails because it cannot tell which source row to apply.

Correct
If Job A's WHEN MATCHED clause were replaced with an unconditional WHEN MATCHED THEN DELETE clause, the two P-100 source rows would not cause the statement to fail.

Both source matches request the same unconditional deletion of the P-100 target row, so the deletion is unambiguous.

Correct
Job B replaces the target rows dated 2026-01-01 through 2026-01-07 with the 500 corrected rows and ignores the 3 rows dated 2026-01-08.

By default every row the query returns must satisfy the REPLACE WHERE predicate. The 3 rows dated 2026-01-08 fall outside it, so the statement fails and writes nothing at all.

Correct
Why

Job A has two P-100 source rows that both qualify for the update against one target row, so the MERGE fails because both source rows request competing updates to the same target row. The only exception is an unconditional DELETE action, where it does not matter which source row triggers the delete. Job B uses REPLACE WHERE, which by default requires every incoming row to satisfy the predicate. Because 3 rows are dated 2026-01-08, the whole statement fails and no rows are replaced or inserted.

Practise this topic until it's automatic.

Ten questions a day, every answer explained, and misses that come back until you beat them.

Start free