Documentation Home
MySQL Shell for VS Code


MySQL Shell for VS Code  /  Getting Started  /  Run Embedded SQL

Pre-General Availability: 2024-05-21

2.5 Run Embedded SQL

If you write a Python application anywhere in Visual Studio Code, and if any of the Python strings within the application contain SQL code, you can establish a link between the string containing the SQL code (indicated by orange arrow-like icons) and the code block of a separate DB Notebook. Changes made in the notebook editor can be sent back to the original SQL code, as long as the Python string it originated from remains unchanged.

Essentially, this feature enables you to write a Python application and to test the embedded SQL code by executing it in a DB Notebook where you can then fix SQL syntax errors, check the actual result, and test different parameters before running the Python application.

To run the embedded SQL statement

  1. Highlight the embedded SQL.

  2. Right-click and select Execute Embedded SQL with MySQL Shell from the menu.

  3. When prompted, type (or select) an existing database connection to use.

The SQL statements are executed and outputted to a new code block in the notebook editor of the connection you selected.

To update SQL in the original source file

  • Right-click the statement and select Update SQL in Original Source File. The edited SQL statement is returned to the original code block and replaces the original SQL statement.