
Ultimate access to all questions.
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
Explanation:
In Databricks notebooks, you can use different languages within the same notebook by using magic commands at the beginning of a cell. The %sql magic command tells Databricks to interpret the cell's content as SQL code, regardless of the notebook's default language.
Why option D is correct:
%sql to the first line of a cell explicitly tells Databricks to execute that cell as SQLWhy other options are incorrect:
%sql would cause a syntax error in a Python notebookKey Takeaway: Databricks notebooks support language-agnostic cells through magic commands (%sql, %python, %scala, %r), allowing data engineers to use the most appropriate language for each task within the same notebook.