# Query files

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 files are SQL and JS files that you can create for a data source in the IDE and store them in an IDE project. In query files, you can write, run, and store your SQL statements. A query file is included in the project context if you choose to store it in the [current project directory](directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html).  Also, query files can be detached from any data source if, for example, your tasks require the files as general SQL statements storage.

![Query file](https://resources.jetbrains.com/help/img/idea/2026.2/query_file_overview.png)

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

You can [associate a query file with a different data source]() using the data source dropdown on the toolbar.

### Location

You can specify the location for a query file when [creating it](#create_a_query_file). If a query file is stored in the [current project directory](directories-used-by-the-ide-to-store-settings-caches-plugins-and-logs.html) or in a directory attached to the project, you can find it 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))) .

![Query files in the tool window](https://resources.jetbrains.com/help/img/idea/2026.2/query_file_overview_tool_window.png)

To store your new query file in another location, specify the directory when creating the query file. You can also move the existing query file to another 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/help/img/idea/2026.2/db_ui_query_file_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/help/img/idea/2026.2/db_ui_query_file_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 file

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

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

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

* 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 File .

Procedure: Open a query 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))) ,  navigate to the query file you want to open, then double-click it.

* In the   Database   tool window ,  expand the data source node, then expand the Query Files folder and double-click the query file you want to open.

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

Procedure: Rename a query file

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

* Right-click a  query file 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 file. By default, it is located at the top of the file tree.

2.  Right-click the file and 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))).

* In the    Database   tool window   :

1.  Expand the data source node and the Query Files folder.

2.

Right-click the query file 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 file](https://resources.jetbrains.com/help/img/idea/2026.2/query_file_rename.png)

Procedure: Delete a query file

1. 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 query file you want to delete.

2.  Right-click the  query file 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)).

2. In the    Database   tool window   :

1.  Expand the data source node and then the Query Files folder.

2.

Right-click the query file and then select Delete (`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/help/img/idea/2026.2/query_file_delete.png)

Procedure: Attach a data source to a query file

To attach a data source to a query file, do the following:

* In code editor:

1. On the toolbar of query file, click the data source dropdown.

2.

Navigate to the All submenu and select the data source you want to associate the query file with.

* In the    Database   tool window   :

1. Navigate to your query file and select it.

2. Right-click the query file and select Attach Data Source.

3. Select the data source you want to associate the query file with.

IntelliJ IDEA automatically associates the query file with the data source you select. After the association, the query file name remains the same and data source is indicated new the query file name in the  Project tool window .

## Query file reference

Find information about query file  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)

