Help home > Running SQL
Running SQL
Write and run SQL in a SQL tab, and view the results and execution plans. Editing features such as formatting and commenting out are included.
What you can do
| Task | How |
|---|---|
| Open a SQL tab | π New SQL on the top bar (Ctrl+N), double-click a connection in the tree, or right-click it β "New SQL Tab" |
| Change the connection | The drop-down at the top left of the SQL tab |
Getting started: running SQL (3 steps)
Open a SQL tab
Double-click a connection in the tree to open a SQL tab for it.Write SQL
Table names are suggested as you type. You can also drag table and column names from the tree.Execute
Press Ctrl+Enter to execute the statement at the cursor. The results appear below.
How to execute
| Action | What is executed |
|---|---|
| βΆ Execute, Ctrl+Enter | The selection if there is one, otherwise the statement at the cursor |
| βΆβΆ Execute All, F5 | The selection if there is one, otherwise every statement in the editor |
Statements run in order, and execution stops at the first error. Before running DROP (of tables, views, etc.), TRUNCATE, ALTER TABLE that drops a column, or UPDATE / DELETE without a WHERE clause, Musubi SQL lists the affected operations and asks you to confirm (you can turn this off in Settings).
Results are loaded up to the "Max" row count (default 1000). If there are more rows, the result tab gets a "+" and "(truncated at β¦ rows)" appears below the grid.
Stopping execution
While SQL is running, a β Stop button appears. Press it to cancel the running SQL; the remaining statements in the script are not executed. The message "Execution was cancelled" appears.
| Connection type | How it is cancelled |
|---|---|
| SQL Server | Cancels the running request (the connection stays open) |
| PostgreSQL | Calls pg_cancel_backend from a separate connection |
| MySQL / MariaDB | Runs KILL QUERY from a separate connection |
| Oracle | Interrupts the running call (ORA-01013) |
| JDBC | Uses the driver's cancel (Statement.cancel) |
SQLite, SQL Server Compact, LocalDB and ODBC cannot be cancelled (the button is disabled). In manual commit mode, changes made by statements before the cancelled one remain in the transaction.
Variables (enter values at run time)
If your SQL contains variables, a dialog asks for their values when you execute it. This is handy when you run the same SQL repeatedly with different values.
| Syntax | How the value is embedded | Example |
|---|---|---|
:name | Numbers as is, everything else as 'text'. You can also choose "NULL" or "As is" | WHERE id = :id AND name = :name |
${name} | Exactly as typed (for table names, parts of conditions, etc.) | SELECT * FROM ${table} |
- Variables with the same name all receive the value you enter once. Previously entered values are remembered per name.
- Text inside strings and comments, PostgreSQL
::typecasts, and:NEWand the like inside stored procedures, triggers and PL/SQL blocks are not treated as variables. - If you do not use variables, turn off "Prompt for SQL variable values (:name, ${name}) when executing" in Settings.
Statement separators
- Statements are separated by
;(a;inside a string or comment does not count). - A line containing only
/(Oracle) or onlyGO(SQL Server) is also a separator. - In MySQL, you can change the delimiter with
DELIMITER //. - Oracle PL/SQL (
BEGIN,CREATE PROCEDURE, etc.) and SQL Server statements that start withDECLARE,CREATE PROCEDUREand so on are not split at;; everything up to the next/orGOruns as one statement.
Results and messages
- Each statement that returns rows gets its own "Result" tab. The "Messages" tab shows, for each statement, success or failure, row counts, elapsed time, errors and PRINT output. Press Clear to empty the messages.
- While running: a busy indicator and the elapsed time (min:sec) appear in the row of result tabs. In SQL Server, messages from
RAISERROR(..., 0, 1) WITH NOWAITappear in the "Messages" tab as soon as they arrive, so you can follow the progress of long jobs (PRINToutput is batched by SQL Server and may not appear right away). Messages received so far are kept even if execution stops with an error or is cancelled. Because many messages slow down the display, the oldest lines beyond "Maximum message lines" in Settings (default 1000) are discarded (while running, they are discarded in chunks of about 100 lines, and the number of omitted lines is shown at the top). - Error location: when execution fails, Musubi SQL estimates where the error is from the error message, marks that spot in the editor with a red squiggle and a marker at the start of the line, and moves the cursor there (hover over the marked line to see the error; editing the SQL clears the marks). PostgreSQL and Oracle report the position, SQL Server reports the line number, and for MySQL, SQLite and others the location is guessed from "near ..." in the message or from column and table names. If the location cannot be determined, no mark is added.
- Column headers show the logical names of the referenced table columns (when the display names are "Logical" or "Both").
- You can select and copy cells just like in Excel. See Working with grids for operations and Export for output.
- Highlight: press "Highlight" at the top right of the result and type some text to highlight cells containing it in yellow (case-insensitive). Enter / Shift+Enter moves to the next / previous cell; Esc or pressing "Highlight" again clears it.
- NOT NULL columns: columns defined as NOT NULL in the referenced table get a light purple background (hover over the header to see "NOT NULL"). Expression columns, and columns whose name also exists as a nullable column in another referenced table, are not colored. Toggle it with "NOT NULL" at the top right of the result or in Settings (shared with the table data screen).
- Primary key columns: primary key columns of the referenced table get a light ochre background (takes precedence over the NOT NULL color). Not applied if a column with the same name is not a primary key in another table. Toggle it with "Primary key" at the top right of the result or in Settings (shared with the table data screen).
- Foreign key columns: foreign key columns of the referenced table get a light teal background (after the primary key color). Not applied if a column with the same name is not a foreign key in another table. Toggle it with "Foreign key" at the top right of the result or in Settings (shared with the table data screen).
Commit and rollback
Turn off "Auto-commit" to switch to manual commit: nothing is committed until you press Commit or Rollback. The status bar shows "Manual commit". This setting is per connection.
Execution plans
Choose from Execution Plan βΎ. The plan is for the statement at the cursor (or the first statement in the selection).
| Type | Key | Description |
|---|---|---|
| Estimated execution plan | Ctrl+E | Shows the plan without executing the SQL. |
| Actual execution plan | Ctrl+Shift+E | Executes the SQL and measures row counts, loops and so on. |
| Database | Estimated | Actual |
|---|---|---|
| SQL Server | SHOWPLAN_ALL (table with estimated costs) | STATISTICS PROFILE |
| PostgreSQL | EXPLAIN | EXPLAIN (ANALYZE, BUFFERS) |
| MySQL | EXPLAIN FORMAT=TREE | EXPLAIN ANALYZE |
| Oracle | DBMS_XPLAN.DISPLAY | DBMS_XPLAN.DISPLAY_CURSOR (SELECT only) |
| SQLite | EXPLAIN QUERY PLAN (shown as a tree) | Not available |
Tree view and problem spots
The plan is shown as a tree of operations (use Tree / Raw Output at the top right of the result to switch to the output exactly as the database returned it).
- Share bars: the share of the total time (actual plan) or cost (estimated plan) spent in that operation alone. The heaviest operation is labeled "Heaviest".
- Likely problems: operations are colored red (serious) or yellow (warning), with the reason below the operation. Click an item in the list at the top to jump to that operation.
| Finding | Typical cause / fix |
|---|---|
| Full scan repeated inside a loop | The join column has no index |
| Full scan despite a filter condition | The WHERE column has no index |
| Estimated and actual row counts differ greatly (actual plan only) | Statistics are stale. Shown only on the operation where the gap starts |
| Sort or hash does not fit in memory | Not enough working memory (such as PostgreSQL's work_mem) |
| No join condition (Cartesian product) | A missing join condition |
| Key lookup (SQL Server) | Can be fixed with an index that INCLUDEs the missing columns |
| Missing statistics and other warnings (SQL Server) | Warnings from SQL Server, shown as is |
Editing features
Use them from the "Edit" menu, the editor's context menu, or the keyboard. Conversions and formatting apply to the selection if there is one, otherwise to the whole editor.
| Feature | Key |
|---|---|
| Find / Find Next / Find Previous | Ctrl+F / F3 / Shift+F3 |
| Replace | Ctrl+H (Ctrl+R also works) |
| Go to Line | Ctrl+G |
| Comment Out / Uncomment | Ctrl+K / Ctrl+Shift+K |
| Format SQL | Ctrl+Q (Ctrl+Shift+F also works) |
Format SQL as One Line (line comments become /* */) | Ctrl+Shift+Q |
| To Uppercase / To Lowercase / Keywords to Uppercase | "Edit" menu β "Convert" |
| Temporary Font Size | "Edit" menu β "Temporary Font Size" |
| Copy Entire Current Result Set / Copy All Result Sets | "Edit" menu (tab-separated, with headers) |
| Copy SQL with Formatting (Colors and Indentation) | Ctrl+Shift+C, the editor's context menu, or the "Edit" menu |
Copy with formatting (for pasting into Excel design documents and the like)
Copies the selected SQL (or all of it if nothing is selected) with its syntax coloring (keywords, strings, comments, etc.) and indentation intact. Format it with Ctrl+Q first for a more readable result.
- Excel cells: each line goes into the next cell down. Indentation and per-character colors are kept. The font is MS Gothic (monospaced).
- Word and PowerPoint: pasted as one block with colors and indentation intact.
- Excel shapes (text boxes): Excel only pastes text from other apps with "Keep Text Only", so colors and fonts are lost (indentation is kept). For colored text, paste into Word first, copy it again from Word, and paste that into the text box.
- Notepad and similar: pasted as plain text without colors.
- The colors are designed for white paper (keywords blue, strings red, comments green, numbers green-ish, functions brown, operators and symbols gray) and do not depend on the app theme (dark).
Find and replace
Works the same as in VS Code. Ctrl+F shows the find box above the editor, and Ctrl+H also shows the replace box (you can toggle it with βΈ / βΎ on the left). If text is selected when you open it, that text is searched for.
- Enter / Shift+Enter moves to the next / previous match (same as F3 / Shift+F3). The number of matches and the current position (such as 3 / 10) are shown.
- Aa: match case, ab: match whole word, .*: use regular expression. An option is on when it is outlined in blue.
- In the replace box, Enter or Replace replaces the next match, and Ctrl+Enter or Replace All replaces all matches. Undo with Ctrl+Z. With regular expressions, you can use the matched groups in the replacement with
$1and so on. - Close it with Esc.
Marking likely errors (Check)
Musubi SQL checks the SQL as you type and marks likely errors with a squiggle and a marker at the start of the line (red: error, yellow: warning). Hover over a mark to see the reason. Toggle it with "Lint" on the toolbar or in Settings.
- Unclosed strings, comments and quotes; unmatched parentheses
- Extra commas; AND / OR / operators with nothing after them; clauses such as WHERE without an expression; GROUP / ORDER without BY
- Clauses in the wrong order (JOIN after WHERE, GROUP BY after ORDER BY, etc.) or repeated
- Aggregate functions in WHERE or GROUP BY,
= NULL(should be IS NULL), JOIN without ON - INSERT with mismatched column and value counts, UPDATE / DELETE without WHERE, misspelled keywords (SELCT, WEHRE, etc.)
Source strings and code stripper
Generate Source String turns SQL into code that embeds it in a program (C#, Java, VB.NET, JavaScript / TypeScript, Python, PHP, Delphi). Example (C#):
FROM t
sql.AppendLine("SELECT 1");
sql.AppendLine("FROM t");
Code Stripper does the reverse: it extracts the strings from program code and turns them back into SQL.
Executing stored procedures
In the tree, right-click a stored procedure or function β "Execute..." to open a dialog for its parameters. Enter the values and press Execute to run it in a SQL tab and show the results. Values of OUTPUT (OUT) parameters are also shown as results (SQL Server, MySQL). Show SQL (Do Not Execute) only generates the call statement. Right-click β "Open Call Statement in SQL Tab" opens a template with every parameter set to NULL.
Execution history
Every SQL statement you execute is recorded automatically, whether it succeeds or fails (up to 2000 entries, newest first). Open the history with History in the SQL tab, π History on the top bar, Ctrl+Shift+H, or by right-clicking a connection in the tree β "SQL Execution History...".
| Task | How |
|---|---|
| Search | Type part of the SQL or a connection name in the box at the top. Separate words with spaces to show only entries that contain all of them. You can also filter with "This connection only" and "Errors only" |
| Insert into the editor | Double-click the row, press Enter, or press Insert into Editor (when opened from a SQL tab; inserts at the cursor) |
| Reopen or re-execute | Open in New Tab / Execute in New Tab (uses the connection recorded with the entry) |
| Delete | Delete (the selected entry) / Delete All |
The list shows the date, connection, SQL, result (rows fetched, rows updated or error) and elapsed time. The full SQL and error details of the selected entry appear below.
Saving and opening files
Save with Ctrl+S and open with Ctrl+O. "File" β "Recent Files" lets you quickly reopen recently opened or saved SQL files and ER diagrams (up to 10). You can also drag and drop .sql files (and .txt and .msqer) from Explorer or elsewhere anywhere onto the window to open them (if a file is already open, its tab is shown). The encoding is detected automatically: UTF-8 (with or without BOM), UTF-16 or Shift_JIS. Tabs with unsaved changes are marked with β, and you are asked to confirm when you close them.
FAQ
The result stops partway through
It is truncated at the "Max" row count. Increase "Max" on the toolbar, or use "Fetch all rows again and export them" in the export dialog.
SET and similar settings do not carry over to the next execution
They do carry over within the same SQL tab (the same connection). They are reset when you disconnect.
β² Back to top