r/mysql • • Sep 11 '26

discussion How should a SQL editor handle multiple statements when you click "Run"?

We're building **LibreDB Studio**, an open-source SQL editor, and one of our volunteer contributors raised an interesting question about how multiple SQL statements should behave when using the Run action.

We're trying to understand the actual habits and expectations of SQL users before making a decision, so I'd really like to hear how you use SQL editors in practice.

For example:

CREATE TABLE test (...);

INSERT INTO test VALUES (...);

SELECT * FROM test;

What would you expect when you click **Run**?

Some possible approaches:

  1. **Run all statements*** `Run` executes everything in the editor.* `Run Selection` can be used when you only want part of it.
  2. **Run the current statement*** `Run` executes the statement where the cursor is.* `Run All` executes the whole editor.
  3. **Selection takes priority*** No selection : current statement* Selection : selected statements* `Run All` is available separately.
  4. Other :)

there are also some interesting edge cases around this, especially when multiple statements are involved: should they run in a transaction by default, or should transaction handling always be explicit?

DBeaver, DataGrip, SSMS, pgAdmin, TablePlus, Toad, PL/SQL Dev, phpMyAdmin, etc. what behavior feels most natural to you? And what behavior are you already used to?

We're continuing the discussion on GitHub as well, if you'd like to see the original question or add to the discussion:

https://github.com/orgs/libredb/discussions/776

0 Upvotes

12 comments sorted by

1

u/Imaginary__Bar Sep 11 '26

Don't you post this earlier today?

1

u/cevheribozoglan Sep 11 '26

I asked about it in r/SQL and got a surprisingly interesting split in the responses.

We're trying to understand how people who actually work with databases think about these workflows before making decisions in the editor.

2

u/Lumethys Sep 11 '26

If people had different opinion, you make it a config

3

u/magicmulder Sep 11 '26

TOAD uses different "run" modes - Shift-F9 runs the statement at cursor, F5 runs all statements etc.

If the question is what should be the default, I would say "all".

1

u/navicat-gu 25d ago

jomofo's "script mode vs scratchpad mode" split matches how I actually work, and I'd design around that rather than picking one universal default.

What feels natural day to day

  1. Cursor / selection first. If nothing is selected, Run = the statement under the cursor (semicolon-bounded). If there is a selection, Run = that selection. Accidental "run the whole file" is how people drop the wrong table.
  2. A separate Run All (or Run Script) for the CREATE + INSERT + SELECT case. Make that one ask for confirmation when the script contains DDL/DML, or at least make it a different shortcut.
  3. Don't auto-wrap everything in a transaction unless the user asked. A script of CREATE + INSERT + SELECT is fine auto-committed statement by statement for exploration; a migration script should be an explicit transaction the user wrote.

Configurable default is fine, but the safe out-of-the-box behavior is "current statement," with Run All one click further away. Power users who want "F5 = everything" will find the setting in thirty seconds; beginners won't recover a DROP they didn't mean to send.

Edge cases worth deciding up front:

  • Statement under cursor with no trailing ; — still run it.
  • Selection that starts mid-statement — either expand to full statements or refuse with a clear error.
  • Mixed SELECT and INSERT in one Run All — show each result set / affected-row count, don't only keep the last one.

Disclosure: I'm RC, Director of Digital Strategy @ Navicat. In Navicat 18, Run executes the current statement (or the selection); running the whole editor is a separate action. That matches the "scratchpad-safe" habit above. Take it as one data point among the tools you're already surveying.

1

u/dutchman76 Sep 11 '26

My personal typical work is one command at the time, i type it hit enter, get result, no errors, move on to the next one.

when I run a whole sequence like that, it's probably a copy & paste from somewhere else, and I wouldn't be waiting for output from each command, so I'd paste and run the whole thing in one shot.

1

u/jomofo Sep 11 '26 • Mindblown

I see it as two different modes. I'll call them "script mode" and "scratchpad mode". If I'm in "script mode" I'm expecting them to run sequentially and perhaps optionally in a single transaction. If I'm in "scratchpad mode" I'm likely troubleshooting something and running several disparate queries that I want to control one-by-one and likely don't want to accidentally execute them all sequentially.

1

u/roXplosion Sep 11 '26

I'd have two buttons; "Run" (runs everything), and "Run Selected" (runs only statements where any part is selected, or the single statement where the cursor is if nothing is explicitly selected).

1

u/SaltineAmerican_1970 Sep 11 '26

Ask me when I click the run button. Allow me to not be asked again.

1

u/Standgrounding Sep 12 '26

Run selection > run all

1

u/SurgioClemente Sep 11 '26

Copy how datagrip does it