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
Open an SQL file in DataGrip.
Click the statement that you want to execute.
Press Ctrl+Enter or select Execute from the context menu.
(Optional) If the SQL file is not associated with a console, select the database console in which you want to execute the statement.
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
Double-click an SQL file to open it in DataGrip.
From the <console> list, select a console file that you want to use.
Click the Run icon (Shift+F10).
Select statements that you want to execute and press Enter.
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.
For example, the Database tool window ( ) displays a list of all available data sources. The Files tool window ( ) includes a list of attached directories, files for extensions (GROOVY scripts), scratch files, and database consoles.
Run an SQL file for one data source
In the Database tool window, right-click a data source.
Select Run SQL Script.
In the Select Path window, navigate to the SQL file that you want to apply.
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).
In the Files tool window, select the necessary SQL file.
Right-click the SQL file, select Run <file_name> (or press Ctrl+Shift+F10).
In the Execution target window, select the necessary data sources.
Attach a directory with SQL files
In the Files tool window, right-click any area and select Attach directory.
Navigate to the directory that you want to attach.
Detach a directory with SQL files
In the Files tool window ( ), right-click a directory and select Detach Directory.
In the notification dialog, click Detach.
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 ( ).
Click a data source and select.
Right-click a data source and select.
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 (), navigate to , double-click a console file.
In the Database tool window, click 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
Place the caret within the statement.
Press Ctrl+Enter. Alternatively, click 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.