
Answer-first summary for fast verification
Answer: They can add `%sql` to the first line of the cell
In Databricks notebooks, you can use language magic commands to specify the language for individual cells. To use SQL in a Python notebook cell, you need to add `%sql` at the beginning of the cell. This tells Databricks to interpret that specific cell as SQL code while keeping all other cells as Python. **Key points:** - Option A is incorrect because it IS possible to use SQL in a Python notebook using magic commands. - Option B is incorrect because attaching to a SQL endpoint is not required for running SQL in a notebook cell. - Option C is incorrect because simply writing SQL syntax without the magic command will result in a syntax error in a Python notebook. - Option D is CORRECT - adding `%sql` to the first line of the cell enables SQL execution in that specific cell. - Option E is incorrect because changing the default language of the notebook would affect all cells, not just the specific cell where SQL is needed. This feature allows data engineers to seamlessly mix SQL and Python within the same notebook, which is a powerful capability of Databricks notebooks for data engineering workflows.
Author: Keng Suppaseth
Ultimate access to all questions.
No comments yet.
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 changes to those cells.
Which of the following describes how the data engineer can use SQL within a cell of their Python notebook?
A
It is not possible to use SQL in a Python notebook
B
They can attach the cell to a SQL endpoint rather than a Databricks cluster
C
They can simply write SQL syntax in the cell
D
They can add %sql to the first line of the cell
E
They can change the default language of the notebook to SQL