
Answer-first summary for fast verification
Answer: ```sql CREATE OR REPLACE TABLE table_name ( id STRING, birthDate DATE, avgRating FLOAT ) ```
## 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: - Create an **empty** Delta table - Use SQL DDL commands - Work **regardless** of whether a table already exists 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.
Author: LeetQuiz .
Ultimate access to all questions.
No comments yet.
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 |
| - | - | - |
A
CREATE OR REPLACE TABLE table_name AS
SELECT
id STRING,
birthDate DATE,
avgRating FLOAT
USING DELTA
CREATE OR REPLACE TABLE table_name AS
SELECT
id STRING,
birthDate DATE,
avgRating FLOAT
USING DELTA
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