DATABRICKS-DATA-ENGINEER-ASSOCIATE practice question 22 of 25

Which of the following commands can be used to write data into a Delta table while avoiding the writing of duplicate records?

Full set: 177 questions
Answer options
A: DROP
B: IGNORE
C: MERGE Correct answer
D: APPEND
E: INSERT
Correct Answer:
C. MERGE
Explanation

The MERGE command is the standard and most effective way to perform "upsert" (update or insert) operations on a Delta table. It allows you to define a matching condition between a source and a target table. By using the WHEN NOT MATCHED THEN INSERT clause, you can specify that only records from the source that do not have a corresponding match in the target table should be inserted. This is the explicit mechanism for writing new data while preventing the creation of duplicate records based on a key or a set of keys.

Why Incorrect

A. DROP: This command deletes an entire table and its data; it does not write or manage individual records.
B. IGNORE: This is not a primary SQL command for writing data. It can be a clause in other statements but is not the tool for conditional inserts.
D. APPEND: This operation adds all records from the source to the target table, which will create duplicates if the records already exist.
E. INSERT: This command adds new rows to a table without checking for pre-existing records, thus leading to duplicates.

References

1. Databricks SQL Language Reference

MERGE INTO: "Merges a set of updates

insertions

and deletions based on a source table into a target Delta Lake table." The documentation explicitly details the WHEN NOT MATCHED [BY TARGET] THEN INSERT clause

which is the mechanism for inserting rows that do not exist in the target.

Source: Databricks Documentation > SQL reference > Data manipulation language > MERGE INTO.

2. Databricks Documentation

"Table deletes

updates

and merges": This guide explains how MERGE is used for complex conditional updates. It states

"You can use MERGE to perform complex operations like deduplicating data...". This directly supports using MERGE to avoid duplicates.

Source: Databricks Documentation > Delta Lake guide > Table deletes

updates

and merges.

3. Databricks Documentation

"Best practices: Delta Lake": In the section on simplifying upserts

the documentation recommends MERGE for inserting or updating records. It contrasts this with more complex

multi-step read/write processes

highlighting MERGE as the atomic and efficient solution for this use case

which includes avoiding duplicate insertions.

Source: Databricks Documentation > Delta Lake guide > Best practices > Upsert into a table using merge.

Scroll to Top