DATABRICKS-CERTIFIED-DATA-ENGINEER-ASSOCIATE · Question #29
A data engineer has a Python notebook in Databricks, but they need to use SQL to accomplish a specific task within a cell. They still want all of the other cells to use Python without making any…
The correct answer is D. They can add %sql to the first line of the cell. Databricks notebooks support magic commands that override the default language on a per-cell basis. Adding %sql as the very first line of a cell instructs the Databricks runtime to interpret that cell's content as SQL, while all other cells continue to run as Python. This is…
Question
Options
- AIt is not possible to use SQL in a Python notebook
- BThey can attach the cell to a SQL endpoint rather than a Databricks cluster
- CThey can simply write SQL syntax in the cell
- DThey can add %sql to the first line of the cell
- EThey can change the default language of the notebook to SQL
How the community answered
(28 responses)- A4% (1)
- C7% (2)
- D89% (25)
Explanation
Databricks notebooks support magic commands that override the default language on a per-cell basis. Adding %sql as the very first line of a cell instructs the Databricks runtime to interpret that cell's content as SQL, while all other cells continue to run as Python. This is the standard approach for mixing languages within a single notebook. Changing the notebook's default language (E) would affect all cells. SQL endpoints (B) are separate compute resources not attachable to individual cells. Writing plain SQL syntax in a Python cell (C) would raise a syntax error.
Topics
Community Discussion
No community discussion yet for this question.