Databricks Data Engineer Associate Question 330
Select 3You are working on a Delta Lake table in Databricks. The table is used to store daily sales data, and you need to update it with new data. You are considering whether to use CREATE OR REPLACE TABLE or INSERT OVERWRITE. Which of the following statements accurately describe the differences between these two operations?
- A
CREATE OR REPLACE TABLEwill drop and recreate the table, removing all existing data and metadata. - B
Using
INSERT OVERWRITEallows you to preserve the table schema while replacing data in specific partitions or the entire table. - C
CREATE OR REPLACE TABLEis more efficient thanINSERT OVERWRITEfor updating large tables because it avoids scanning existing data. - D
INSERT OVERWRITEcannot be used with Delta Lake tables. - E
CREATE OR REPLACE TABLEis typically used for creating a new table or resetting an existing table, whereasINSERT OVERWRITEis used to modify data within the existing table.
Show answer and explanation
Correct answers: A, B, E
Explanation
CREATE OR REPLACE TABLE and INSERT OVERWRITE have distinct purposes. CREATE OR REPLACE TABLE is destructive, as it deletes the existing table and metadata before recreating it. This is typically used when starting fresh. On the other hand, INSERT OVERWRITE is non-destructive to the table schema and allows for data replacement within the table (or specific partitions). Understanding these differences is essential for choosing the right operation for your use case.
- A. Correct.
Correct:
CREATE OR REPLACE TABLEdrops the existing table and recreates it, removing all current data and metadata. - B. Correct.
Correct:
INSERT OVERWRITEallows you to keep the table structure intact while replacing data, either in specific partitions or the entire table. - C. Incorrect.
Incorrect: While
CREATE OR REPLACE TABLEcan be used to reset a table, it is not necessarily more efficient thanINSERT OVERWRITEfor updates. Efficiency depends on the specific use case and data size. - D. Incorrect.
Incorrect:
INSERT OVERWRITEis fully supported with Delta Lake tables, and it can be used for partitioned or non-partitioned tables. - E. Correct.
Correct:
CREATE OR REPLACE TABLEis used for creating or resetting a table, whileINSERT OVERWRITEis used to replace the data without recreating the table.