DEA-C01 · Question #165
A data engineer needs to create a new empty table in Amazon Athena that has the same schema as an existing table named old_table. Which SQL statement should the data engineer use to meet this…
The correct answer is D. CREATE TABLE new_table AS (SELECT * FROM old_table) WITH NO DATA. To create an empty Amazon Athena table with the same schema as an existing table, a specific SQL syntax is required.
Question
A data engineer needs to create a new empty table in Amazon Athena that has the same schema as an existing table named old_table. Which SQL statement should the data engineer use to meet this requirement?
Options
- ACREATE TABLE new_table AS SELECT * FROM old_tables;
- BINSERT INTO new_table SELECT * FROM old_table;
- CCREATE TABLE new_table (LIKE old_table);
- DCREATE TABLE new_table AS (SELECT * FROM old_table) WITH NO DATA;
How the community answered
(51 responses)- A4% (2)
- B2% (1)
- C8% (4)
- D86% (44)
Why each option
To create an empty Amazon Athena table with the same schema as an existing table, a specific SQL syntax is required.
`CREATE TABLE new_table AS SELECT * FROM old_tables;` would create `new_table` with the same schema as `old_table` but would also copy all the data from `old_table`, which contradicts the requirement for an *empty* table.
`INSERT INTO new_table SELECT * FROM old_table;` is used to populate an *existing* table with data and does not create the table itself.
`CREATE TABLE new_table (LIKE old_table);` is a SQL syntax often found in PostgreSQL or similar databases for creating a table with a similar schema, but it is not the standard or recommended method in Amazon Athena (which uses Presto/Trino SQL dialect for CTAS).
The `CREATE TABLE AS (SELECT * FROM old_table) WITH NO DATA;` statement in Amazon Athena creates a new table (`new_table`) with a schema identical to the result of the `SELECT` query, but crucially, the `WITH NO DATA` clause ensures that no data is copied into the new table, leaving it empty as required.
Concept tested: Athena CREATE TABLE AS SELECT WITH NO DATA
Source: https://docs.aws.amazon.com/athena/latest/ug/create-table-as-select.html
Topics
Community Discussion
No community discussion yet for this question.