Run files
SQL files are run against the selected databases or schemas using run configurations. Depending on your purposes, you can run SQL files using one of the following ways:
Create new run configurations or edit the existing ones via a run configuration widget.
Create new run configurations via Files tool window by running the selected file.
Create new run configurations via Database Explorer by running a file against the selected database or schema.
For information about run configurations, see Using run/debug configurations.
Run an SQL file
Open the Run/Debug Configuration dialog in one of the following ways:
Select
from the main menu.With the Navigation bar visible ( ), choose from the run/debug configuration selector.
Press Alt+Shift+F10 and then press 0.
In the Run/Debug Configuration dialog, you can either create a new run configuration or edit an existing one.
To create a new run configuration, click the Add New Configuration icon () and select Database Script.
To edit an existing run configuration, expand the Database Script node and select the run configuration that you want to edit from the list.
The fields that appear in the right-hand pane display the settings for the selected configuration type.
Target data source / schema: databases or schemas against which you want to run your database scripts. This setting is dialect-dependent.
If you select a data source as a target, DataGrip displays a schema in which the script will be run. It is the default schema.
Script files: SQL files that you want to run. To add files, click the Add button () and navigate to files that you want to run. If a script contains schema switching, you will see a warning ().
Click OK to apply the changes and close the dialog.
To run the configuration, click the Run <configuration_name> button ().
In the Files tool window ( ), right-click the SQL file that you want to run, and select Run '<file_name>'. Alternatively, press Alt+Shift+R.
Select the settings for your run configuration.
Target data source / schema: databases or schemas against which you want to run your database scripts. This setting is dialect-dependent.
If you select a data source as a target, DataGrip displays a schema in which the script will be run. It is the default schema.
Script files: SQL files that you want to run. To add files, click the Add button () and navigate to files that you want to run. If a script contains schema switching, you will see a warning ().
Click Run.
In the Database Explorer ( ) , right-click a data source, or a schema and select .
In the file browser window that opens, navigate to the SQL file that you want to run and click Open.
Select the settings for your run configuration.
Target data source / schema: databases or schemas against which you want to run your database scripts. This setting is dialect-dependent.
If you select a data source as a target, DataGrip displays a schema in which the script will be run. It is the default schema.
Script files: SQL files that you want to run. To add files, click the Add button () and navigate to files that you want to run. If a script contains schema switching, you will see a warning ().
Click Run.
Open the Files tool window, navigate to the SQL file, and select it.
Drag the SQL file to the data source or schema in Database Explorer that you want to run it against.
Select the settings for your run configuration.
Target data source / schema: databases or schemas against which you want to run your database scripts. This setting is dialect-dependent.
If you select a data source as a target, DataGrip displays a schema in which the script will be run. It is the default schema.
Script files: SQL files that you want to run. To add files, click the Add button () and navigate to files that you want to run. If a script contains schema switching, you will see a warning ().
Click Run.
You can run single files using a dedicated option on the toolbar. The run and debug buttons are active and allow you to instantly run the currently opened file.
In the editor, open the file that you want to run.
Click next to the Current File option on the toolbar.
Select the settings for your run configuration.
Target data source / schema: databases or schemas against which you want to run your database scripts. This setting is dialect-dependent.
If you select a data source as a target, DataGrip displays a schema in which the script will be run. It is the default schema.
Script files: SQL files that you want to run. To add files, click the Add button () and navigate to files that you want to run. If a script contains schema switching, you will see a warning ().
Click Run.
You can access other runners from the submenu as well: expand the list and click the right arrow next to Current File. From the menu that opens, you can open the run configuration to specify more options.
Run an SQL file for several data sources
In the Files tool window (Alt+2), select file or files that you want to run.
Right-click the selection and invoke Run <configuration_name> (or press Control+Shift+F10). This action creates a temporary run configuration.
In the Edit Configuration window that opens, click Add in the Target data source / schema pane and select data sources or schemes against which you want to run the selected files.
You can click Recent to select data sources that you used recently.
Click Run.
View output
When you run a file or use a run configuration, the output is shown in the tab of a Run tool window. For more information about the tool window controls, refer to Run tool window.
Tips and tricks
Execute a file from the search dialog
Press Shift twice.
In the Search Everywhere dialog, type the filename.
Select a file by using Up and Down arrows.
Press Control+Shift+F10.
In the Edit Configuration window, click the Add button () and select data sources or schemes against which you want to run selected files.