WebStorm 2023.3 Help

Run SQL 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 Project tool window by running the selected file.

  • Create new run configurations via Database tool window by running a file against the selected database or schema.

In WebStorm, the maximum number of DML statements that you can run from an SQL file is 1000.

Run an SQL file

  1. Open the Run/Debug Configuration dialog in one of the following ways:

    • Select Run | Edit Configurations from the main menu.

    • With the Navigation bar visible (View | Appearance | Navigation Bar), choose Edit Configurations from the run/debug configuration selector.

    • Press Alt+Shift+F10 and then press 0.

  2. In the Run/Debug Configurations 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 (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.

  3. 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, WebStorm 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 (the Add button) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (Warning).

  4. You can either run the configuration right away, or save the configuration to run it later.

    • Click OK to save the run configuration for later and close the dialog.

    • To run the configuration right away, click Run.

Run files by using run/debug configurations
  1. In the Project tool window ( View | Tool Windows | Project) , right-click the SQL file that you want to run, and select Run '<file_name>'. Alternatively, press Alt+Shift+R.

    Run SQL files from the Project tool window
  2. 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, WebStorm 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 (the Add button) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (Warning).

    Edit Configuration dialog
  3. Click Run.

  1. In the Database tool window ( View | Tool Windows | Database) , right-click a data source, or a schema and select SQL Scripts | Run SQL Script.

    Run an SQL file from the Database tool window
  2. In the file browser window that opens, navigate to the SQL file that you want to run and click Open.

  3. 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, WebStorm 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 (the Add button) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (Warning).

    Edit Configuration dialog
  4. Click Run.

  1. Open the Project tool window, navigate to the SQL file, and select it.

  2. Drag the SQL file to Database tool window to the data source, database, or schema that you want to run it against.

  3. 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, WebStorm 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 (the Add button) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (Warning).

    Edit Configuration dialog
  4. 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.

  1. In the editor, open the file that you want to run.

  2. Click Run next to the Current File option on the toolbar.

  3. 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, WebStorm 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 (the Add button) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (Warning).

    Edit Configuration dialog
  4. Click Run.

You can access other runners as well: expand the list and select Current File. From the widget that opens, you can debug the code, run it with coverage, or open the run configuration to specify more options.

Run an SQL file for several data sources

  1. In the Project tool window ( View | Tool Windows | Project) , select file or files that you want to run.

  2. Right-click the selection and invoke Run <file_names> (or press Ctrl+Shift+F10). This action creates a temporary run configuration.

  3. In the Edit Configuration window that opens, click the Add button (the Add icon) 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 the Recent button (the Recent icon) to select data sources that you used recently.

    Run an SQL file for several data sources
  4. 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.

File run output

Change a data source and a connection session

  1. Detach a file from the current connection session. To detach the file, click Detach Session from the Sessions list.

  2. From the list of dialects, select another dialect.

  3. From the Sessions list, select a connection session of this dialect.

Tips and tricks

Execute a file from the search dialog

  1. Press Shift twice.

  2. In the Search Everywhere dialog, type the filename.

  3. Select a file by using Up and Down arrows.

  4. Press Ctrl+Shift+F10.

  5. In the Edit Configuration window, click the Add button (the Add icon) and select data sources or schemes against which you want to run selected files.

Last modified: 20 February 2024