Skip to content

SQL Editor

DBeaverDevOps edited this page Aug 1, 2024 · 15 revisions

Table of contents

With the SQL Editor in CloudBeaver, you can write and execute multiple SQL scripts within a single database connection, save them as files, and reuse them later.

Getting started

To start working with the SQL Editor, you have two options:

  1. Create a new SQL script:

    • click Open SQL Editor button in the top toolbar. For more information about toolbar, see Toolbar in CloudBeaver.
  2. Open recent SQL script:

    • Select Tools -> Show scripts from the top toolbar.
    • A Resource manager window appears. Click any script to open it in a new tab. For more information see Resource manager.

SQL Editor overview

The SQL Editor contains the Script panel, the Result panel, and the Toolbar.

Script panel

The Script Panel is the primary area where you can write, edit, and manage your SQL scripts. It provides basic text editing features with the added benefits of specialized functionalities tailored for SQL development:

Results Panel

The results panel displays tabs with results in various formats. The tabs resulting from script execution represent instances of the Data Editor. You can create, edit and execute SQL scripts in the script panel and then see the results in the result tabs.

Toolbar

The Toolbar in the SQL Editor is equipped with various buttons:

Button name Icon Description Additional resource
Execute SQL statement Executes the SQL statement.
Execute SQL statement in new tab Executes the SQL statement in a new tab.
Execute SQL script Executes all SQL statements in the script panel.
Explain execution plan Provides a detailed explanation of the SQL execution plan. Query Execution Plan
Show server output Displays the server-side output, specific to the database being used.
AI prompt Generates SQL code based on natural language prompts. AI Smart Assistance
Save as script Saves the current SQL script to a file. Saving Scripts
Format SQL script Formats the SQL script. Formatting Guide
Download SQL script Downloads the SQL script to the local machine.
Upload SQL script Uploads a SQL script from your local machine to the SQL Editor.

Statement Execution

Place the cursor on the line with the statement or select part of the script to execute the statement. Click on the Execute SQL statement icon in the left toolbar or use the Ctrl+Enter shortcut. The result of the statement execution will be shown under the script editor area. Results will be grouped (Result - 1 <1>, Result - 1 <2>) if statement execution is finished with more than one result.

Script Execution

Click on the Execute SQL script icon in the left toolbar or use the Alt+X shortcut to execute the script. The summary result will be shown in the Statistics tab, and results will be shown in separate Result tabs.

Resource manager

To manage SQL scripts on the server, use the Resource Manager. For a more detailed guide on using this feature, see Resource Manager.

Auto and Manual commit

By default, all database connections in the SQL Editor operate in Auto-commit mode, meaning that changes are automatically committed after each SQL statement is executed. To gain precise control over your transactions, you may switch to Manual commit mode.

Switching to Manual commit

In Manual commit mode, you manually determine when to commit or rollback transactions. This mode is essential when batch operations need to be treated as a single unit or when you need to inspect changes before making them permanent.

Here is a table outlining the actions and their corresponding icons in Manual commit mode:

Action Icon Description
Switch to manual commit Click to open a menu for manual transaction control. You will need to Commit or Rollback changes explicitly.
Commit Click after executing SQL statements to save the changes to the database.
Rollback Click to revert changes made by your SQL statements, undoing current transaction changes.
Switch to auto-commit Click to return to Auto-commit mode, where changes are automatically committed.

Tip: After committing in Manual commit mode, performing a Refresh is necessary to see the newly added data in the Result tab.

Limitations of Rollback capabilities

In database management, not all commands support rollback operations. It is crucial to understand that Data Definition Language (DDL) commands—such as CREATE, DROP, or ALTER cannot be reversed with transactions for some databases. This means that once these commands are executed, they cannot be reversed even in manual commit mode.

Important: Always check the transaction support for the specific database you are working with to avoid irreversible operations.

SQL Editor preferences

To configure the SQL Editor, navigate to Settings -> Preferences or Settings -> Administration -> Global Preferences.

Setting Description
Insert table aliases (in FROM clause) Controls how aliases are inserted. Options:
Disable: No aliases will be automatically inserted.
my_table mt: Inserts the alias mt for the table my_table.
my_table AS mt: Inserts AS mt explicitly as the alias.
Use long object names (schema/catalog) Includes schema or catalog details in table names for clarity.

Shortcuts

Shortcut Description
Ctrl+Enter Execute SQL statement
Ctrl+</kbd> or Ctrl+Shift+Enter Execute SQL statement in new tab
Alt+X Execute script
Shift+Ctrl+E Show execution plan
Alt+T Open SQL Editor in separate browser tab
Shift+Ctrl+F Format script
Ctrl+Z or CMD+Z Undo
Ctrl+Y or Ctrl+Shift+Z or Shift+CMD+Z or CMD+Y Redo
Esc+Tab Remove focus from the SQL Editor

CloudBeaver Documentation

User Guide

Installation

Configuration

CloudBeaver AWS

CloudBeaver Enterprise Edition

Team Edition

Deployment

Clone this wiki locally