IntelliJ IDEA 2026.1 Help

Query files

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.

  1. Press Ctrl+Alt+S 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 files that you can create in the IDE and store in an IDE project. In query files, you can write SQL queries and execute them against an attached data source and schema. 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

For more information about working with query results in query files, refer to Query results.

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

Location

By default, query files are created in the current project directory. In the IDE, you can find query files in the Project tool window (Alt+1) .

Query consoles in the tool window

To store your new query file in another location, specify the directory when creating the file. You can also move the existing file to another directory.

Code editor

The code editor is where you compose your SQL statements using the resolve modes and coding assistance features, and execute them against the associated data source.

Find the code editor toolbar controls in Code editor controls. Read more about the editor in Editor basics.

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

  • If the executed statement does not retrieve data, results are displayed in the Output tab.

    Query console with an active Result tab of Services tool window
    1. Query console tab toolbar.

    2. Code editor.

    3. Services tool window.

    4. Output and Result tabs. Result tab is active.

    5. Result tab toolbar.

    Query console with an active Output tab of Services tool window
    1. Query console tab toolbar.

    2. Code editor.

    3. Services tool window.

    4. Output and Result tabs. Output tab is active.

    5. Right toolbar of the Output tab.

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, and select Query File.

Open a query file

  • By default, query files are stored in the current project directory. In the Project tool window, navigate to the directory at the top of the file tree, then double-click the query file you want to open.

  • 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

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) :

    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).

  • 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).

Rename a query file

Delete a query file

  1. In the Project tool window (Alt+1) :

    1. Navigate to the query file you want to delete.

    2. Right-click the query file and select Delete. Alternatively, press Delete.

  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 Rename (Shift+F6).

Rename a query console

Configure query file settings

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 console, 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.

Change the SQL dialect in the code editor

  • Right-click the editing area and select Change Dialect (<current_dialect>) to. In the Change SQL Dialect window, select a dialect.

Query file reference

Find information about query file context menu and toolbar buttons in the Code editor tips and reference topic.

Read more about code editor in Editor basics.

09 March 2026