Open a SQL file as a Console in DataGrip Open a SQL file as a Console in DataGrip database database

Open a SQL file as a Console in DataGrip


There is a new option in DataGrip 2017.2 : Attach console.

You can find via Ctrl+Shift+A or by opening the context menu for a file. After performing this action, this file can be run against the console. Switching consoles will be useful if you want to run the same script in several data sources.

enter image description here


Here is the documentation from "Running SQL Script Files" help page for DataGrip 2016.3 to run your own file and get results, as if running SQL from a console.

It appears that any changes to your file are saved automatically, even if the script is not executed, and then previous versions are available through "Local History" which is a feature of most if not all of the JetBrains IDE's.

Executing individual statements

When running individual statements contained in an SQL file:– The statements can contain parameters. Prior to running such statements DataGrip will ask you to specify the parameter values.

On the other hand:– The statements are run for only one data source at a time.

To run a statement or statements:

  1. Open the SQL file of interest in the editor.
  2. Place the cursor within the statement you want to execute. If you want to run more than one statement, select (highlight) the necessary statements.

  3. Do one of the following: – Press Ctrl + Enter or select Execute from the context menu.– Press Alt + Enter or click the Intention Bulb, and select Run query in console.

  4. Select the database console to be used.

The statement or statements are executed using the selected console. The corresponding console is associated with the file. The name of the associated console is shown on the Status bar.