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.
- One keystroke to:
- Select the current block (bounded by empty lines, optionally
GO
), and - execute it via your SQL extension.
- Select the current block (bounded by empty lines, optionally
- 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.
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
-
Open a
.sql
file and connect with your database extension. -
Place the cursor anywhere inside a block like:
-- Block A SELECT TOP 5 * FROM sys.tables -- Block B SELECT 1 AS x
-
Press Ctrl+Shift+E.
The extension selects the current block (between blank lines) and runs it.
Enable in settings:
"runSqlBlock.treatGoAsSeparator": true
Then this treats GO
lines as block boundaries:
SELECT * FROM dbo.Customers
GO
SELECT * FROM dbo.Orders
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
}
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.
-
“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.
- For SQL Server use:
-
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.
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.