Databricks Data Engineer Associate Question 332
Select 4You are working on a Databricks project where you need to refresh a Delta table with new data from a source table. The Delta table should completely replace its previous content with the new data. However, you also want to retain the schema and metadata of the Delta table. Which of the following statements correctly describe the differences and use cases between CREATE OR REPLACE TABLE and INSERT OVERWRITE in this scenario?
- A
CREATE OR REPLACE TABLE will drop and recreate the table, potentially removing existing metadata like table comments and constraints.
- B
INSERT OVERWRITE will replace the data in the table without affecting the table's schema or metadata.
- C
CREATE OR REPLACE TABLE is suitable when you need to replace both the schema and data of a table.
- D
INSERT OVERWRITE cannot be used with Delta tables, as Delta does not support overwriting data.
- E
INSERT OVERWRITE is more efficient than CREATE OR REPLACE TABLE when only the data needs to be replaced.
Show answer and explanation
Correct answers: A, B, C, E
Explanation
CREATE OR REPLACE TABLE is used when you need to redefine a table entirely, including its schema and data, but it will drop and recreate the table, possibly removing metadata. INSERT OVERWRITE, on the other hand, only replaces the data in the table while preserving the schema and metadata, making it more efficient for use cases where only data needs to be updated.
- A. Correct.
CREATE OR REPLACE TABLE will recreate the table, which can remove metadata like comments or constraints. This is true.
- B. Correct.
INSERT OVERWRITE replaces the data without modifying the table's schema or metadata. This is true.
- C. Correct.
CREATE OR REPLACE TABLE replaces both the schema and data of a table, making it suitable when you need to redefine the table completely. This is true.
- D. Incorrect.
INSERT OVERWRITE is supported with Delta tables and can be used to overwrite data. This statement is false.
- E. Correct.
INSERT OVERWRITE is typically more efficient than CREATE OR REPLACE TABLE when you only need to update the data, as it avoids recreating the table. This is true.