DataGrip 2026.1 Help

Query files

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

You can specify the location for a query file when creating it. If a query file is stored in the current project directory or in a directory attached to the project, you can find it in the Files tool window (Alt+2) .

Query files in the tool window

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

Create a query file

To create a query file, use one of the following actions in the Database Explorer (⌘ 1) .

  • 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

  • In the Files tool window (Alt+2) , navigate to the query file you want to open, then double-click it.

  • In the Database Explorer, 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 Files tool window (Alt+2) :

    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 Explorer (⌘ 1) :

    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 Files tool window (Alt+2) :

    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 Explorer (⌘ 1) :

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

    2. Right-click the query file and then select Delete (Delete).

Delete a query console

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 Explorer (⌘ 1) :

    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.

Associate a query file with a different data source

DataGrip 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 Files tool window.

query file associated with a different data source

Query file reference

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

Read more about code editor in Editor basics.

13 March 2026