Table of contents
- Getting started
- SQL Editor overview
- Script panel
- Spelling
- Hyperlinks
- Highlighting
- Toolbar
- Results Panel
- Multiple results in one tab
- Additional features
- Active Database
- Layout Adjustment
- Outline
- Error indication
- Features summary
With the SQL Editor in DBeaver, you can write and execute multiple SQL scripts within a single database connection, savethem as files, and reuse them later.
Getting startedTo start working with the SQL Editor, you have several options:
Via Database Navigator:
- Navigate to your desired database connection in the Database Navigator view.
- Press F4 or go to SQL Editor -> Open SQL script from the main menu, or right-click on theconnection and choose Open SQL script from the context menu.
- A Choose SQL Script window appears. Click any script to open it in a new tab.
Open Recent SQL script:
- Right-click on your database connection and select SQL Editor -> Recent SQL script from the context menu or go to SQLEditor -> Recent SQL script from the main menu. Alternatively use the Ctrl+Enter shortcut in the Database Navigator view.
- A Choose SQL Script window appears. Click any script to open it in a new tab.
Create a New SQL Script:
- Navigate to SQL Editor -> New SQL Editor on the main menu.
- Press F3 and click New Script in the Choose SQL Script window.
Note: SQL Editor for a connection is different from SQL console for a table or view. Unlike the console, it can savescripts and changes made to them.
You can see all your saved SQL scripts in the Project Explorer view in the Scripts folder.
SQL Editor overviewThe SQL Editor contains the Script panel, the Toolbar, and the Result panel.
Script panelTip: You can open the SQL editor preferences by pressing Alt+Enter or right-click and navigate toPreferences.
The Script Panel is the primary area where you can write, edit, and manage your SQL scripts. It provides basic textediting features with the added benefits of specialized functionalities tailored for SQL development:
The panel includes a spelling checker to identify and highlight misspelled words, assisting you inmaintaining the quality of your scripts. For more information check out our article.
HyperlinksYou can press and hold Ctrl and at the same time move the mouse over the SQL text. If DBeaver recognizes someidentifier as a table/view name, it presents it as a hyperlink. You can click the hyperlink to open this object`seditor:
HighlightingDBeaver uses SQL syntax highlighting which depends on the database associated with the script. Different databases havedifferent sets of reserved keywords and system functions. For more information, see the relevant section on highlightingsettings in our article on SQL Code Editor.
ToolbarThe toolbar is customizable and contains buttons for commonly used commands. For more information on customization,see our article on toolbar customization.
Results PanelThe results panel displays tabs with results in various formats. The tabs resulting from script execution representinstances of the Data Editor. You can create, edit and execute SQL scripts in the script panel andthen see the results in the result tabs.
Multiple results in one tabYou can view and manage multiple query results within a single tab.
To use the Multiple results feature in the SQL Editor, follow these steps:
Add Toolbar Item: Add the Toggle execution result orientation to the SQL Editor toolbar.
Alternatively:
- Right-click in the SQL Editor window and navigate to Execute -> Toggle execution result orientation.
- Navigate to SQL Editor -> Toggle execution result orientation.
Toggle: Click the toolbar item to activate multiple query results view.
View results:
- To view multiple results in a single tab, execute queries using the Execute SQL Script button .
- You can collapse some result sets according to your preference by clicking the arrow button .
Additional featuresActive DatabaseImportant: When using two or more queries in parallel, exercise caution as this may lead to client UI freeze, highdatabase server load, or transaction deadlock.
You can change the connection associated with the current SQL editor or change the active database/schema, at the sametime retaining the SQL text.
To change the connection, press Ctrl+9 or click the Active datasource box on DBeaver`s main toolbar:
The Select Data Source dialog box opens. In the tree of connections, click the required connection and then clickSelect. To disassociate the SQL Editor with any connection, click None:
To change the active schema, press Ctrl+0 or click the Active Catalog/Schema box in DBeaver`s maintoolbar:
The Choose catalog/schema dialog box opens. In the list of schemas, double-click the required schema:
If there are many schemas, and they do not fit in the dialog box use the search field to find the schema.
To configure the set of columns to be visible for each schema in the dialog box, click the Configure columnsbutton .
Layout AdjustmentTip: You can easily associate the SQL Editor with the connection that is currently in focus in the Database Navigator (thefocus can be on any object of the connection - a table, a folder, etc.) - click the Link with editor or use the shortcut Ctrl+Shift+,.
You can modify the layout of the SQL Editor by showing/hiding the results panel and changing the horizontal/verticalposition of the panes.
- To toggle (hide/show) the results panel, press CTRL+6 or right-click anywhere in the script pane and, onthe context menu, click Layout -> Toggle results panel.
- To maximize the results panel, press CTRL+Shift+T, or double-click the results tab name, or right-clickanywhere in the script panel and, on the context menu, click Layout -> Maximize results panel.
- To switch between the script panel and the results pane, press Ctrl+Alt+T or right-click anywhere in the scriptpanel and, on the context menu, click Layout -> Switch active panel.
To position both panels horizontally, right-click anywhere in the script panel and, on the context menu, clickLayout -> Horizontal.
To position both panels vertically, right-click anywhere in the script panel and, on the context menu, click Layout ->Vertical.
You can use the Outline feature in the SQL Editor to get a structured view of your SQL query.
Here's how you can access the Outline:
- Use the shortcut: Alt+Shift+Q, O (on macOS use ⌥⌘Q O).
- Click on the Toggle Outline button in the SQL Editor bottom toolbar.
- Select Panels -> Toggle outline from the Script panel.
- Select SQL Editor -> Panels -> Toggle outline from Menu bar.
When you open the Outline, it shows a tree structure of your SQL query. This representation reflects the components ofyour SQL query and is beneficial for analyzing and moving through large queries. The relationship between the Outlineand SQL Editor is interactive:
- The tree selection in the Outline automatically follows the cursor movement in the SQL Editor. This synchronizationhelps you identify the specific section of the query you are editing within its overall structure.
Alternatively, clicking an item in the Outline tree will highlight the corresponding fragment in the SQL Editor,facilitating swift navigation to different parts of your SQL query.
The SQL Editor indicates errors during the execution of an incorrect query by displaying an erroricon to the left of the query text. Hovering over this icon reveals a tooltip.
- Tooltip: A tooltip will show a detailed list of errors.
- Error list: Moving the mouse over an error in the list will highlight it directly in the query.
- Error types: The SQL Editor detects and displays server issues, semantic errors, and spelling mistakes.
Features summaryNote: Semantic errors are displayed only when the Enable semantic analysis setting is activated and thedatabase in use is relational. For more information,see Query analysis settings.
The SQL Editor offers a variety of advanced features to enhance your scripting experience.
Feature | Description | More Info |
---|---|---|
SQL Templates | Pre-defined SQL code snippets for quick insertion. | SQL Templates |
SQL Assist and Auto-Complete | Helps complete SQL queries by suggesting options. | SQL Assist and Auto-Complete |
AI SQL Assistance | Uses AI to suggest optimizations and best practices. | AI SQL Assistance (ChatGPT) |
SQL Formatting | Automatically formats SQL queries to improve readability. | SQL Formatting |
SQL Execution | Provides various options to execute SQL queries. | SQL Execution |
SQL Terminal | A terminal interface for executing SQL commands. | SQL Terminal |
Variables | Manage variables within your SQL queries. | Variables Panel Pre-configured variables |
Query Execution Plan | Visualize the execution plan of your SQL queries. | Query Execution Plan |
Visual Query Builder | A graphical interface for building SQL queries. | Visual Query Builder |
Script Management | Manage multiple SQL scripts within a single editor. | Script Management |
Client-Side Commands | Execute client-side commands within the editor. | Client-Side Commands |