
Ultimate access to all questions.
A data architect has determined that a table of the following format is necessary:
employeeId startDate avgRating
a1 2009-01-06 5.5
a2 2018-11-21 7.1
...
employeeId startDate avgRating
a1 2009-01-06 5.5
a2 2018-11-21 7.1
...
Which code block is used by SQL DDL command to create an empty Delta table in the above format regardless of whether a table already exists with this name?
A
CREATE OR REPLACE TABLE table_name ( employeeId STRING, startDate DATE, avgRating FLOAT )
B
CREATE OR REPLACE TABLE table_name WITH COLUMNS ( employeeId STRING, startDate DATE, avgRating FLOAT ) USING DELTA
C
CREATE TABLE IF NOT EXISTS table_name ( employeeId STRING, startDate DATE, avgRating FLOAT )
D
CREATE TABLE table_name AS SELECT employeeId STRING, startDate DATE, avgRating FLOAT
Explanation:
Option A is correct because:
CREATE OR REPLACE TABLE which ensures the table is created regardless of whether it already existsWhy other options are incorrect:
Option B: Uses non-standard WITH COLUMNS syntax which is not valid SQL DDL. While USING DELTA explicitly specifies the Delta format, the WITH COLUMNS clause is incorrect.
Option C: Uses CREATE TABLE IF NOT EXISTS which only creates the table if it doesn't exist. This violates the requirement "regardless of whether a table already exists with this name" because it won't replace an existing table.
Option D: Uses CREATE TABLE ... AS SELECT which creates a table populated with data from a SELECT statement, not an empty table. Additionally, the SELECT syntax is incorrect for defining column types.
Key Points:
CREATE OR REPLACE TABLE is the correct approach when you want to ensure a fresh table regardless of existing stateUSING DELTA is optional but can be added for clarity