IntelliJ IDEA 2016.2 Help

Running SQL Script Files

You can run an SQL file as a whole. You can also execute individual statements contained in an SQL file.

Running an SQL file

When running an SQL script file as a whole:

  • You don't need to open the file in the editor. You can select the necessary file in the Project tool window.
  • You can run the file for more than one data source at once.

On the other hand:

  • The statements with parameters won't run.
  • Retrieved data for the SELECT statements won't be shown.

To run an SQL file:

  1. Select the necessary SQL file in the Project tool window, or open the file in the editor.
  2. Do one of the following:
    • Select Run "<file_name>" from the context menu.
    • Press Ctrl+Shift+F10.
  3. In the Choose Data Source pop-up, click the data source to which the script should be applied.

    If you want to run the script for more than one data source, select the data sources of interest in the pop-up and press Enter.

    RunSQLScriptSelectDS

Executing individual statements

When running individual statements contained in an SQL file:

  • The statements can contain parameters. Prior to running such statements IntelliJ IDEA 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 intentionBulb, and select Run query in console.
  4. Select the database console to be used.
    DBSQLAltEnterChooseConsole

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.

DBConsoleAttached

After that, the Execute and the Run query in console commands start to work differently:

  • When using the Execute command, the associated console is used.
  • When using the Run query in console command, IntelliJ IDEA asks you to select the console (as before).

You can use the menu on the Status bar to associate the file with a different console.

DBConsoleMenu

<detach> in this menu removes the association between the file and the console.

For the Execute command options, see Execute in Console.

See Also

Language and Framework-Specific Guidelines:

Last modified: 5 September 2016