nerdexam
Databricks

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…

Submitted by the_admin· Apr 18, 2026ELT with Spark SQL and Python

Question

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?

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)
  • A
    4% (1)
  • C
    7% (2)
  • D
    89% (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

#Databricks Notebooks#Magic Commands#Mixed Language Notebooks#SQL in Python

Community Discussion

No community discussion yet for this question.

Full DATABRICKS-CERTIFIED-DATA-ENGINEER-ASSOCIATE Practice