DEA-C01 · Question #198
A data engineer needs to create an empty copy of an existing table in Amazon Athena to perform data processing tasks. The existing table in Athena contains 1,000 rows. Which query will meet this…
The correct answer is B. CREATE TABLE new_table. To create an empty copy of an existing table in Amazon Athena, which means copying only the table's schema without any data, the most direct and specific SQL DDL command is CREATE TABLE LIKE.
Question
A data engineer needs to create an empty copy of an existing table in Amazon Athena to perform data processing tasks. The existing table in Athena contains 1,000 rows. Which query will meet this requirement?
Options
- ACREATE TABLE new_table
- BCREATE TABLE new_table
- CCREATE TABLE new_table
- DCREATE TABLE new_table
How the community answered
(57 responses)- A4% (2)
- B79% (45)
- C12% (7)
- D5% (3)
Why each option
To create an empty copy of an existing table in Amazon Athena, which means copying only the table's schema without any data, the most direct and specific SQL DDL command is `CREATE TABLE LIKE`.
While `CREATE TABLE AS SELECT ... LIMIT 0;` can create an empty table by inferring schema from an empty result set, it uses the CTAS statement which is primarily for creating and populating tables, making `CREATE TABLE LIKE` a more explicit schema-copying command.
The `CREATE TABLE new_table LIKE existing_table;` statement is the most direct and idiomatic SQL DDL command in Amazon Athena specifically designed to create a new, empty table that replicates the schema (column names, data types, and partition keys) of an existing table without copying any data.
The syntax `CREATE TABLE new_table (LIKE existing_table);` with parentheses around `LIKE existing_table` is not a valid SQL DDL syntax for creating a table in Athena or standard SQL.
Similar to option A, `CREATE TABLE AS SELECT ... WHERE 1=0;` also uses a CTAS statement to create an empty table based on an empty result set, but `CREATE TABLE LIKE` is the dedicated DDL for schema duplication without data.
Concept tested: Athena Create Table Like syntax
Source: https://docs.aws.amazon.com/athena/latest/ug/create-table-like.html
Topics
Community Discussion
No community discussion yet for this question.