DataGrip 2019.1 Help

Run a query

A query is a set of instructions that you use to work with database data. In DataGrip, you can run a query from the SQL file or a database console.

A database console is an SQL file that is already associated with a data source. It means that you can start running your queries right away.

For SQL files, you need to attach a console first. Attaching a console to the SQL file means that objects will be associated with the data source of this console and queries will be run in the context of this console.

If a file or a console has several statements, you can select whether you want to run all the statements or only an individual statement.

Run an individual statement

  1. Open an SQL file in DataGrip.

  2. Click the statement that you want to execute.

  3. Press Ctrl+Enter or select Execute from the context menu.

  4. (Optional) If the SQL file is not associated with a console, select the database console in which you want to execute the statement.

  5. In the Statements window, press Enter to run the statement. Otherwise, navigate to another entry to run all statements.

Run a query from the editor

You can open and run an SQL file from the editor. Limitation for the SQL file size is 20 MB. When you open a file that is larger than 20 MB, you see only first 2.5 MB of the file.

Run an SQL file from the editor

  1. Double-click an SQL file to open it in DataGrip.

  2. From the <console> list, select a console file that you want to use.

  3. Click the Run icon (Shift+F10).

  4. Select statements that you want to execute and press Enter.

Run existing SQL files

Run a query from a tool window

Tool windows are editor tabs that provide access to file and data source management, searching, running, integration with version control systems, and other tasks. To see a list of all the tool windows, navigate to View | Tool Windows.

For example, the Database tool window (View | Tool Windows | Files) displays a list of all available data sources. The Files tool window (View | Tool Windows | Files) includes a list of attached directories, files for extensions (GROOVY scripts), scratch files, and database consoles.

Run an SQL file for one data source

  1. In the Database tool window, right-click a data source.

  2. Select Run SQL Script.

  3. In the Select Path window, navigate to the SQL file that you want to apply.

Run an SQL file

Run an SQL file for several data sources

To run an SQL file for several data sources, attach a directory with the necessary files in the Files tool window (see Managing directories).

  1. In the Files tool window, select the necessary SQL file.

  2. Right-click the SQL file, select Run <file_name> (or press Ctrl+Shift+F10).

  3. In the Execution target window, select the necessary data sources.

Run an SQL file for several data sources

Managing directories

Attach a directory with SQL files

  1. Navigate to View | Tool Windows | Files.

  2. In the Files tool window, right-click any area and select Attach directory.

  3. Navigate to the directory that you want to attach.

  4. Click OK.

Detach a directory with SQL files

  1. In the Files tool window (View | Tool Windows | Files), right-click a directory and select Detach Directory.

  2. In the notification dialog, click Detach.

Detach a directory with SQL files

Run a query from a database console

When you create a data source, a database console is created automatically. For more information about database consoles, see Database consoles.

Create a database console

To create a console, use one of the following actions in the Database tool window (View | Tool Windows | Database).

  • Click a data source and select File | New | Console.

  • Right-click a data source and select New | Console.

  • Click a data source, press Alt+Insert, and select Console.

  • Click a data source, press Ctrl+Shift+F10, and select New console.

Open a console

  • In the tool window (View | Tool Windows | ), navigate to Scratches and Consoles | Database Consoles | <data_source_name>, double-click a console file.

  • In the Database tool window, click the Jump to console icon (the Jump to console icon ) and select a console.

  • Click a data source, press F4, and select the console that you need.

Execute an SQL statement

  1. Place the caret within the statement.

  2. Press Ctrl+Enter. Alternatively, click the Execute icon The Execute icon on the toolbar.

    If you have several statements, select whether you want to execute all statements or a single statement. The suggestion list always contains an item for running all the statements.

Save a console as a file

In the console file, press Ctrl+Shift+S. Navigate to the directory where you want to store the file.

Save the console contents as a file
Last modified: 25 July 2019