Databricks Data Engineer Associate exam dumps

Databricks Data Engineer Associate practice question 313 of 532

Databricks Certified Data Engineer Associate. Associate level, Databricks. Free question with the correct answer and a full explanation.

Databricks Data Engineer Associate Question 313

Single answer

You are working with a Delta table named sales_data in Databricks. The table contains the columns product_id, price, and quantity_sold. You are tasked to add a new column total_revenue that automatically calculates the product of price and quantity_sold whenever a new row is inserted or updated. Which of the following commands will correctly create a generated column for total_revenue in the Delta table?

  1. A

    ALTER TABLE sales_data ADD COLUMN total_revenue DOUBLE GENERATED ALWAYS AS (price * quantity_sold)

  2. B

    ALTER TABLE sales_data ADD COLUMN total_revenue DOUBLE DEFAULT (price * quantity_sold)

  3. C

    ALTER TABLE sales_data ADD COLUMN total_revenue DOUBLE GENERATED ALWAYS AS (price * quantity_sold) STORED

  4. D

    ALTER TABLE sales_data ADD GENERATED COLUMN total_revenue DOUBLE AS (price * quantity_sold)

Show answer and explanation

Correct answer: C

Explanation

In Delta tables, generated columns are created using the syntax ADD COLUMN <column_name> <data_type> GENERATED ALWAYS AS (<expression>) STORED. This ensures the column is automatically calculated based on the specified expression and persisted in the table. The correct answer includes the required GENERATED ALWAYS AS clause and the STORED keyword, making it the valid option.

  • A. Incorrect.

    This is close, but it is missing the required STORED keyword, which is necessary for defining a generated column in a Delta table.

  • B. Incorrect.

    This is invalid because DEFAULT is not used to create a generated column. DEFAULT is used to provide a fallback value, not for dynamic calculations.

  • C. Correct.

    This is the correct syntax for adding a generated column in a Delta table. The GENERATED ALWAYS AS clause defines the expression, and the STORED keyword ensures the column is materialized and persisted.

  • D. Incorrect.

    This is invalid syntax because the ADD GENERATED COLUMN clause is not supported in Delta tables.

Timed practice exam

Take a Databricks Data Engineer Associate practice test under exam conditions

45 questions in 90 minutes, drawn from this bank, with a score report and a per-question review when you finish.

Start timed exam