# Query consoles

Procedure: Enable the Database Tools and SQL plugin

This functionality relies on the  Database Tools and SQL plugin, which  is bundled and enabled in IntelliJ IDEA   by default. If the relevant features are not available, make sure that you did not disable the plugin.

> **Note:**
> Database Tools and SQL functionality support is limited in IntelliJ IDEA without the Ultimate subscription.

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Plugins`.

2. Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.

## Overview

Query consoles are SQL and JS files are created for a data source automatically, always attached to it, and stored outside an IDE project. You can write and execute SQL statements in query consoles the same way as you do it in terminal. Query consoles are not included in the project context.

![Query console](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_query_console_overview.png)

For more information about working with query results in query consoles, refer to  [Query results](viewing-query-results.html).

When you create a data source, a query console is created automatically and attached to this data source by default. If necessary, you can create additional query consoles for this data source.

### Database connection session

For each query console, a database [connection session](managing-connection-sessions.html) is created automatically. You can create new connection sessions and attach your query console to existing ones in the [console toolbar](code-editor-tips-and-ref-db-tools-and-sql.html#toolbar_controls).

### Location

All the created query consoles are located in the internal `Database Consoles` directory. To open this directory, open the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS)))  and navigate to `Scratches and Consoles | Database Consoles`.

On your machine, query consoles are stored in the `consoles` subdirectory of the [IDE configuration directory](directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html#config-directory).

### Code editor

The code editor is where you compose your SQL statements using the [resolve modes](run-a-query.html#resolve_modes) and coding assistance features, and execute them against the associated data source.

Find the code editor toolbar controls in [Code editor controls](#reference). Read more about the editor in [Editor basics](using-code-editor.html).

### SQL statement execution

When you execute a statement, the Services tool window opens. The Services tool window displays available connection sessions, Output and Result tabs.   For more information about the tool window, refer to  the [Services tool window](services-tool-window.html) topic.

* If the executed statement retrieves data (for example, `SELECT`), results are displayed in the Result tab that has a title of a qualified table name. For more information about creating custom titles for result tabs, refer to [Use custom titles for tabs with results](viewing-query-results.html#use-custom-titles-for-tabs-with-results).

* If the executed statement does not retrieve data, results are displayed in the Output tab. Result tab: ![Query console with an active Result tab of Services tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_ui_query_console_result_tab.png) 1. [Code editor toolbar](null). 2. [](null). 3. Services tool window. 4. [Output](services-tool-window.html#db_output_tab) and [Result](services-tool-window.html#db_result_tab) tabs. Result tab is active. 5. [Result tab toolbar](services-tool-window.html#db_result_tab_toolbar). Output tab: ![Query console with an active Output tab of Services tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_ui_query_console_output_tab.png) 1. [Code editor toolbar](null). 2. [](null). 3. Services tool window. 4. [Output](services-tool-window.html#db_output_tab) and [Result](services-tool-window.html#db_result_tab) tabs. Output tab is active. 5. [Right toolbar of the Output tab](services-tool-window.html#db_output_tab_right_toolbar).

Procedure: Create a query console

To create a query console , use one of the following actions in the    Database   tool window   .

* Select a data source and select `File | New | Query Console` from the main menu.

* Right-click a data source and select `New | Query Console`.

* Select a data source, press `Alt+Insert` (Windows), `⌘ N` (macOS), `⌃ N` (IntelliJ IDEA Classic (macOS)), `⌘ N` (macOS System Shortcuts), `Alt+Insert` (XWin), `Alt+Insert` (GNOME), `Alt+Insert` (KDE), `Alt+Insert` (Emacs), `Ctrl+N` (Sublime Text), `⌘ N` (Sublime Text (macOS)), `Alt+Insert` (NetBeans), `Ctrl+N` (Visual Studio), `⌘ N` (Visual Studio (macOS)), `Alt+Insert` (Eclipse), `⌘ N` (Eclipse (macOS)), and select  Query Console  .

* Select a data source, press `Ctrl+Shift+F10` (Windows), `⌘ ⇧ F10` (macOS), `⌘ ⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F10` (macOS System Shortcuts), `Ctrl+Shift+F10` (XWin), `Ctrl+Shift+F10` (GNOME), `Ctrl+Shift+F10` (KDE), `Ctrl+Shift+F10` (Emacs), `Ctrl+Shift+F10` (Sublime Text), `⌘ ⇧ F10` (Sublime Text (macOS)), `Ctrl+Shift+F10` (NetBeans), `Ctrl+Shift+F10` (Visual Studio), `⌘ ⇧ F10` (Visual Studio (macOS)), `Ctrl+Shift+F10` (Eclipse), `⌘ ⇧ F10` (Eclipse (macOS)), and select New Query Console.

* Select a data source and press `Ctrl+Shift+Q` (Windows), `⌘ ⇧ L` (macOS), `⌘ ⇧ Q` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ L` (macOS System Shortcuts), `Ctrl+Shift+Q` (XWin), `Ctrl+Shift+Q` (GNOME), `Ctrl+Shift+Q` (KDE), `Ctrl+Shift+Q` (Emacs), `Ctrl+Shift+L` (Sublime Text), `⌘ ⇧ L` (Sublime Text (macOS)), `Ctrl+Shift+Q` (NetBeans), `Ctrl+Shift+Q` (Visual Studio), `⌘ ⇧ L` (Visual Studio (macOS)), `Ctrl+Shift+Q` (Eclipse), `⌘ ⇧ L` (Eclipse (macOS)).

> **Note:**
> Query consoles  can share a single session or use separate sessions.  For more information about session control, refer to  [Manage sessions](managing-connection-sessions.html#manage_sessions).

Procedure: Open a query console

* In the  Project tool window ,  navigate to the    `Scratches and Consoles | Database Consoles` internal directory  . Expand the data source group that includes your query console, then double-click the query console you want to open.

* In the   Database   tool window ,  click ![the Jump to Query Console icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/database-plugin.icons.expui.sqlScript.svg) Jump to Query Console, navigate to the All submenu, and double-click the query console you want to open.

* To open the default query console of a data source, click the data source and press `F4` (Windows), `⌘ ↓` (macOS), `F4` (IntelliJ IDEA Classic (macOS)), `F4` (macOS System Shortcuts), `F4` (XWin), `F4` (GNOME), `F4` (KDE), `F4` (Emacs), `F4` (Sublime Text), `F4` (Sublime Text (macOS)), `F4` (NetBeans), `F4` (Visual Studio), `⌘ ↓` (Visual Studio (macOS)), `F12` (Eclipse), `F3` (Eclipse (macOS)).

![Open a query console](https://resources.jetbrains.com.cn/help/img/idea/2026.2/open_query_console.png)

Procedure: Duplicate a query console

You can duplicate a query console in the following ways:

* Right-click the editor tab header of the query console and select Duplicate.

* Right-click anywhere in the editor area and select Duplicate.

![Duplicate a query console](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_query_console_duplicate_header.png)

Procedure: Rename a query console

To rename a query console , do one of the following:

* Right-click a query console  tab and select Rename File.

* In the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) :

1.  Navigate to the    `Scratches and Consoles | Database Consoles` internal directory  .

2.   Expand a data source group that includes your query console.

3.

Right-click the query console and then select Rename (`Shift+F6` (Windows), `⇧ F6` (macOS), `⇧ F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⌥ R` (macOS System Shortcuts), `Shift+F6` (XWin), `Shift+F6` (GNOME), `Shift+F6` (KDE), `Shift+F6` (Emacs), `Shift+F6` (Sublime Text), `⇧ F6` (Sublime Text (macOS)), `Ctrl+R` (NetBeans), `Ctrl+R, R` (Visual Studio), `⌘ R, R` (Visual Studio (macOS)), `Alt+Shift+R` (Eclipse), `⇧ F6` (Eclipse (macOS))).

![Rename a query console](https://resources.jetbrains.com.cn/help/img/idea/2026.2/rename_query_console_file.png)

Procedure: Change the default name

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Tools | Database | Query Files and Consoles`.

2.

3. In Default file name, specify a new name for the query consoles.

4. Apply the changes and close the dialog.

![Customize how query console names are displayed in editor tab headers](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_settings_query_console_default_name.png)

Procedure: Customize the name in editor tab header

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Tools | Database | Query Files and Consoles`.

2. In the Template field, type your template.

To add more details to the name, use variables. Place the caret where you want to insert the detail and click the corresponding variable button.

3. Apply the changes and close the dialog.

To use this template for query files, too, select Use this template for query files.

![Customize how query console names are displayed in editor tab headers](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_settings_query_console_tab_name_custom.png)

Procedure: Group consoles under the data source directory

1. Open the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS)))  and navigate to the    `Scratches and Consoles | Database Consoles` internal directory  .

2. Right-click a data source group where you want to create a new directory, then select `New | Directory`.

3. Specify a name of the directory.

4. Select and drag query consoles to the directory.

5. In the Move dialog, click Refactor.

![Group consoles under the data source directory](https://resources.jetbrains.com.cn/help/img/idea/2026.2/group_consoles_under_the_data_source_directory.png)

Procedure: Delete a query console

* In the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) :

1.  Navigate to the    `Scratches and Consoles | Database Consoles` internal directory  .

2.   Expand a data source group that includes your query console.

3.  Right-click the query console  and select Delete. Alternatively, press `Delete` (Windows), `⌦` (macOS), `⌦` (IntelliJ IDEA Classic (macOS)), `⌦` (macOS System Shortcuts), `Delete` (XWin), `Delete` (GNOME), `Delete` (KDE), `Delete` (Emacs), `Delete` (Sublime Text), `⌦` (Sublime Text (macOS)), `Delete` (NetBeans), `Delete` (Visual Studio), `⌦` (Visual Studio (macOS)), `Delete` (Eclipse), `⌦` (Eclipse (macOS)).

![Rename a query console](https://resources.jetbrains.com.cn/help/img/idea/2026.2/query_console_delete.png)

Procedure: Copy a query console to a new location

1. In the  Project tool window ,  navigate to the    `Scratches and Consoles | Database Consoles` internal directory  .

2. Expand a data source group that includes your query console.

3. Right-click a query console and select `Refactor | Copy File…`.

4. In the To directory field, specify a new location for the query console.

![Copy a query console to another location](https://resources.jetbrains.com.cn/help/img/idea/2026.2/copy_a_console_file_to_a_new_location.png)

Procedure: Open a query console in the file browser

To open a query console in your file browser, do one of the following:

* Right-click a query console tab and navigate to `Open In | <file_browser>`.

* Open the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS)))  and navigate to the    `Scratches and Consoles | Database Consoles` internal directory  . Expand a data source group that includes your query console. Right-click the query console, and select `Open In | <file_browser>`.

![Open a query console in the file browser](https://resources.jetbrains.com.cn/help/img/idea/2026.2/open_console_in_file_browser.png)

Procedure: Set the default schema

When you select the default schema for a query console, you can omit the name of that schema or database in your statements.

* To set the default schema or database, click the <schema> dropdown located in the upper-right part of the toolbar. Then, select the schema that you need.

For more information about schemas, refer to  the [Schemas](schemas.html) topic.

![Select the default schema or database](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_select_default_schema.png)

## Query console reference

Find information about  query console context menu and toolbar buttons in the [Code editor tips and reference](code-editor-tips-and-ref-db-tools-and-sql.html) topic.

Read more about code editor in [Editor basics](using-code-editor.html).

## See also

### Language and Framework-Specific Guidelines

[Database Tools and SQL](relational-databases.html)

### Procedures

[Run queries](run-a-query.html) [Query results](viewing-query-results.html)

### Reference

[Query execution page](query-execution.html) [Code editor tips and reference](code-editor-tips-and-ref-db-tools-and-sql.html)

