
Ultimate access to all questions.
Question 9
A data architect has determined that a table of the following format is necessary:
| id | birthDate | avgRating |
|---|---|---|
| a1 | 1990-01-06 | 5.5 |
| a2 | 1974-11-21 | 7.1 |
| - | - | - |
B
CREATE OR REPLACE TABLE table_name (
id STRING,
birthDate DATE,
avgRating FLOAT
)
```_
CREATE OR REPLACE TABLE table_name (
id STRING,
birthDate DATE,
avgRating FLOAT
)
```_
C
CREATE TABLE IF NOT EXISTS table_name (
id STRING,
birthDate DATE,
avgRating FLOAT
)
```_
CREATE TABLE IF NOT EXISTS table_name (
id STRING,
birthDate DATE,
avgRating FLOAT
)
```_
D
CREATE TABLE table_name AS
SELECT
id STRING,
birthDate DATE,
avgRating FLOAT
```_
CREATE TABLE table_name AS
SELECT
id STRING,
birthDate DATE,
avgRating FLOAT
```_
E
CREATE OR REPLACE TABLE table_name WITH COLUMNS (
id STRING,
birthDate DATE,
avgRating FLOAT
) USING DELTA
```_
CREATE OR REPLACE TABLE table_name WITH COLUMNS (
id STRING,
birthDate DATE,
avgRating FLOAT
) USING DELTA
```_
Next
Explanation:
Let's analyze each option:
Option A: Uses CREATE OR REPLACE TABLE ... AS SELECT - This creates a table from a SELECT statement, but it's not creating an empty table. The SELECT statement would need to return data.
Option B: ✅ CORRECT - Uses CREATE OR REPLACE TABLE with explicit column definitions in parentheses. This creates an empty Delta table with the specified schema and will replace any existing table with the same name.
Option C: Uses CREATE TABLE IF NOT EXISTS - This only creates the table if it doesn't exist, so it doesn't meet the requirement of creating the table "regardless of whether a table already exists with this name."
Option D: Uses CREATE TABLE ... AS SELECT - Similar to option A, this creates a table from a SELECT statement, not an empty table.
Option E: Uses invalid syntax - WITH COLUMNS is not valid SQL syntax for table creation in Databricks.
The key requirements are:
Option B satisfies all these requirements by using CREATE OR REPLACE TABLE with explicit column definitions, which creates an empty table with the specified schema and replaces any existing table.