Databricks Data Engineer Associate Question 511
Single answerYou are working in a Databricks workspace with a catalog named 'main', a schema named 'sales', and a table named 'transactions'. How would you query the table using SQL in a Databricks notebook?
- A
SELECT * FROM transactions;
- B
SELECT * FROM sales.transactions;
- C
SELECT * FROM main.sales.transactions;
- D
SELECT * FROM main.transactions;
Show answer and explanation
Correct answer: C
Explanation
In Databricks, a three-layer namespace consists of catalog, schema, and table. To query a table, you must use the fully qualified name, which includes all three components. In this scenario, the correct query is 'SELECT * FROM main.sales.transactions;' because it specifies the catalog ('main'), schema ('sales'), and table ('transactions').
- A. Incorrect.
This query is incorrect because it does not specify the schema or catalog. In a three-layer namespace, you must include the catalog and schema before the table name.
- B. Incorrect.
This query is incorrect because it only specifies the schema and table but omits the catalog. A three-layer namespace requires all three components: catalog, schema, and table.
- C. Correct.
This query is correct because it includes all three components of the three-layer namespace: catalog (main), schema (sales), and table (transactions).
- D. Incorrect.
This query is incorrect because it omits the schema, which is required when referencing a table in a three-layer namespace.