Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Run SQL BlockNew to Visual Studio Code? Get it now.
Run SQL Block

Run SQL Block

iamhazel

|
3 installs
| (0) | Free
Selects the SQL block (between blank lines) under the cursor and runs it.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Run SQL Block

VS Code extension to select and execute the SQL block between blank lines (or optionally GO commands) under your cursor with your database extension (configurable).

This is a recreation for VS Code of “Run Query Section” from QE Boost by dzsquared for Azure Data Studio.

Watch Demo

Features

  • One keystroke to:
    1. Select the current block (bounded by empty lines, optionally GO), and
    2. execute it via your SQL extension.
  • Default keybinding: Ctrl+Shift+E (only when the editor has focus).
  • Works with SQL Server (mssql) by default; configurable for Postgres/MySQL/etc.
  • Option to treat GO as a separator.

Requirements

You need a database extension that provides a “run query” command, e.g.:

  • SQL Server: SQL Server (mssql) → command mssql.runQuery
  • PostgreSQL: your Postgres extension’s command (often postgres.runQuery)
  • MySQL: your MySQL extension’s command

Usage

  1. Open a .sql file and connect with your database extension.

  2. Place the cursor anywhere inside a block like:

    -- Block A
    SELECT TOP 5 * FROM sys.tables
    
    -- Block B
    SELECT 1 AS x
    
  3. Press Ctrl+Shift+E.
    The extension selects the current block (between blank lines) and runs it.

Using GO as a separator (optional)

Enable in settings:

"runSqlBlock.treatGoAsSeparator": true

Then this treats GO lines as block boundaries:

SELECT * FROM dbo.Customers
GO
SELECT * FROM dbo.Orders

Settings

Open Settings → Extensions → Run SQL Block or edit JSON:

{
  // The command to run after selecting the block.
  // Default works for the official SQL Server (mssql) extension.
  "runSqlBlock.commandToRun": "mssql.runQuery",

  // Limit execution to these languages. Empty = allow all.
  "runSqlBlock.languages": ["sql", "mysql", "postgres", "tsql"],

  // Treat lines containing only 'GO' (case-insensitive) as block separators.
  "runSqlBlock.treatGoAsSeparator": false
}

Keybinding

Default:

{
  "key": "ctrl+shift+e",
  "command": "runSqlBlock.execute",
  "when": "editorTextFocus"
}

Note: VS Code’s Explorer also uses Ctrl+Shift+E, but this binding only applies when the editor has focus, so the Explorer remains usable. Change it if you prefer another key.

Troubleshooting

  • “command ‘…’ not found”
    Your DB extension isn’t installed/active, or the command ID is different.

    • For SQL Server use: "runSqlBlock.commandToRun": "mssql.runQuery".
    • For other databases, set the command ID provided by that extension.
  • Nothing runs
    Ensure you’re connected to a database in your DB extension and your cursor is inside a non-empty block.

  • Multi-cursor
    Currently operates on the primary cursor/selection.

Contributing

Issues and PRs welcome. I don't have any experience managing a public repository but I'll try my best! Repo: https://github.com/iamhazel/run-sql-block

Please include your VS Code version and the database extension/command you’re using.

License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft