# Run SQL files

Procedure: Enable the Database Tools and SQL plugin

This functionality relies on the  Database Tools and SQL plugin, which  is bundled and enabled in IntelliJ IDEA   by default. If the relevant features are not available, make sure that you did not disable the plugin.

> **Note:**
> Database Tools and SQL functionality support is limited in IntelliJ IDEA without the Ultimate subscription.

1. Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Plugins`.

2. Open the Installed tab, find the Database Tools and SQL plugin, and select the checkbox next to the plugin name.

> **Note:**
> This page describes how to run SQL files using the Database Tools and SQL plugin.   For more information about running applications and other files, refer to  [Run applications](running-applications.html).

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 IntelliJ IDEA, the maximum number of DML statements that you can run from an SQL file is 1000.

## Run an SQL file

Run widget:

Procedure:

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](guided-tour-around-the-user-interface.html#navigation-bar) visible (`View | Appearance | Navigation Bar`), choose `Edit Configurations` from the run/debug configuration selector.

* Press `Alt+Shift+F10` (Windows), `⌃ ⌥ R` (macOS), `⌥ ⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌃ ⌥ R` (macOS System Shortcuts), `Alt+Shift+F10` (XWin), `Alt+Shift+F10` (GNOME), `Alt+Shift+F10` (KDE), `Alt+Shift+F10` (Emacs), `Alt+Shift+F10` (Sublime Text), `⌃ ⌥ R` (Sublime Text (macOS)), `Alt+Shift+F10` (NetBeans), `Ctrl+Alt+Shift+R` (Visual Studio), `⌘ ⌥ ⇧ R` (Visual Studio (macOS)), `Alt+Shift+F10` (Eclipse), `⌃ ⌥ R` (Eclipse (macOS)) and then press `0` (Windows), `0` (macOS), `0` (IntelliJ IDEA Classic (macOS)), `0` (macOS System Shortcuts), `0` (XWin), `0` (GNOME), `0` (KDE), `0` (Emacs), `0` (Sublime Text), `0` (Sublime Text (macOS)), `0` (NetBeans), `0` (Visual Studio), `0` (Visual Studio (macOS)), `0` (Eclipse), `0` (Eclipse (macOS)).

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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) 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, IntelliJ IDEA 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (![Warning](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.warning.svg)).

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

* To save the run configuration for later, click OK.

* To run the configuration right away, click Run.

![Run files by using run/debug configurations](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_run_debug_configurations_script_files.png)

Project tool window:

Procedure:

1. In the  Project tool window ,  right-click the SQL file that you want to run, and select Run '<file_name>'. Alternatively, press `Alt+Shift+R` (Windows), `⌘ ⌃ R` (macOS), `⌘ ⌃ R` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ R` (macOS System Shortcuts), `Alt+Shift+R` (XWin), `Alt+Shift+R` (GNOME), `Alt+Shift+R` (KDE), `Alt+Shift+R` (Emacs), `Alt+Shift+R` (Sublime Text), `⌘ ⌃ R` (Sublime Text (macOS)), `Alt+Shift+R` (NetBeans), `Alt+Shift+R` (Visual Studio), `Alt+Shift+R` (Visual Studio (macOS)), `Alt+Shift+G` (Eclipse), `⌘ ⌃ R` (Eclipse (macOS)).

![Run SQL files from the Project tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run_sql_files_from_project_tool_window.png)

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, IntelliJ IDEA 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (![Warning](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.warning.svg)).

![Edit Configuration dialog](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_run_configuration_select_target.png)

3. Click Run.

Database tool window:

Procedure:

1. In the   Database   tool window ,  right-click a data source, or a schema and select `SQL Scripts | Run SQL Script…`.

![Run an SQL file from the Database tool window](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run_sql_file_from_database_tool_window.png)

2. In the file browser window that opens, navigate to the SQL file that you want to run .

3. Click Open.

You can view the output in the Run tool window.   For more information about tool window controls, refer to  [Run tool window](run-tool-window.html).

Drag the file:

Procedure:

1. Open the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) , 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.

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.2/drag_script_file_to_run.mp4)

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, IntelliJ IDEA 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (![Warning](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.warning.svg)).

![Edit Configuration dialog](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_run_configuration_select_target.png)

4. Click Run.

Run current file:

Procedure:

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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.execute.svg) 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, IntelliJ IDEA 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) and navigate to files that you want to run. If a script contains schema switching, you will see a warning (![Warning](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.warning.svg)).

![Edit Configuration dialog](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_run_configuration_select_target.png)

4. Click Run.

You can access the other run modes by expanding the list. From the widget that opens, you can debug the code, run it with coverage, profile it, or open the run configuration to specify more options.

Procedure: Run an SQL file for several data sources

1. In the  Project tool window ,  select file or files that you want to run.

2. Right-click the selection and invoke Run <file_names> (or press `Ctrl+Shift+F10` (Windows), `⌃ ⇧ R` (macOS), `⌃ ⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ R` (macOS System Shortcuts), `Ctrl+Shift+F10` (XWin), `Ctrl+Shift+F10` (GNOME), `Ctrl+Shift+F10` (KDE), `Ctrl+Shift+F10` (Emacs), `Ctrl+Shift+F10` (Sublime Text), `Ctrl+Shift+F10` (Sublime Text (macOS)), `Alt+Shift+F6` (NetBeans), `Ctrl+Alt+F5` (Visual Studio), `⌃ ⌥ F5` (Visual Studio (macOS)), `Ctrl+Shift+F10` (Eclipse), `⌃ ⇧ R` (Eclipse (macOS))). This action creates a temporary run configuration.

3. In the Edit Configuration window that opens, click the Add button (![the Add icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) 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](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.vcs.history.svg)) to select data sources that you used recently.

![Run an SQL file for several data sources](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_run_sql_files_select_data_source.png)

4. Click Run.

## Data source attachment

Procedure: Attach an SQL file to a data source

* From the <data sources> list in the top right corner, select the data source that you want to attach the file to.

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_attach_sql_file_to_data_source.mp4)

Procedure: Switch data sources for an SQL file

* To attach the file to another data source, click the data sources list and select the other one. Alternatively, in the Sessions tool window, right-click the file name, select Switch Data Source, then select the data source.

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_switch_data_sources_for_sql_file.mp4)

Procedure: Detach an SQL file from a data source

* To detach a file from data source, click the data sources list and select Detach Data Source.

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_detach_sql_file_from_data_source.mp4)

## Stop execution

Procedure:

* In the Run tool window, click ![the Stop button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.stop.svg) Stop on the toolbar. Alternatively, press `Ctrl+F2` (Windows), `⌘ F2` (macOS), `⌘ F2` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ .` (macOS System Shortcuts), `Ctrl+F2` (XWin), `Ctrl+F2` (GNOME), `Ctrl+2` (KDE), `Ctrl+F2` (Emacs), `Ctrl+F2` (Sublime Text), `Ctrl+F2` (Sublime Text (macOS)), `Shift+F5` (NetBeans), `Shift+F5` (Visual Studio), `⇧ F5` (Visual Studio (macOS)), `Ctrl+F2` (Eclipse), `⌘ F2` (Eclipse (macOS)) and select the process to stop.

This performs a forceful termination of the program, meaning that the usual cleanup mechanisms at the operating system, virtual machine, and application levels may be bypassed, possibly preventing the execution of shutdown hooks, proper resource releasing, logging, and so on.

## 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](run-tool-window.html).

![File run output](https://resources.jetbrains.com.cn/help/img/idea/2026.2/db_file_run_output.png)

Procedure: Pause output

* Right-click in the Run tool window and select Pause Output from the context menu. Use the same toggle to resume the program.

![Pause output](https://resources.jetbrains.com.cn/help/img/idea/2026.2/pause_output.png)

> **Note:**
> Only the output is suspended. Pausing the output does not affect the execution of the program.

## Tips and tricks

Procedure: Execute a file from the search dialog

1. Press `Shift` (Windows), `Shift` (macOS), `Shift` (IntelliJ IDEA Classic (macOS)), `Shift` (macOS System Shortcuts), `Shift` (XWin), `Shift` (GNOME), `Shift` (KDE), `Shift` (Emacs), `Shift` (Sublime Text), `Shift` (Sublime Text (macOS)), `Shift` (NetBeans), `Shift` (Visual Studio), `Shift` (Visual Studio (macOS)), `Shift` (Eclipse), `Shift` (Eclipse (macOS)) 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` (Windows), `⌃ ⇧ R` (macOS), `⌃ ⇧ F10` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ R` (macOS System Shortcuts), `Ctrl+Shift+F10` (XWin), `Ctrl+Shift+F10` (GNOME), `Ctrl+Shift+F10` (KDE), `Ctrl+Shift+F10` (Emacs), `Ctrl+Shift+F10` (Sublime Text), `Ctrl+Shift+F10` (Sublime Text (macOS)), `Alt+Shift+F6` (NetBeans), `Ctrl+Alt+F5` (Visual Studio), `⌃ ⌥ F5` (Visual Studio (macOS)), `Ctrl+Shift+F10` (Eclipse), `⌃ ⇧ R` (Eclipse (macOS)).

5. In the Edit Configuration window, click the Add button (![the Add icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg)) and select data sources or schemes against which you want to run selected files.

[Video](https://resources.jetbrains.com.cn/help/img/idea/2026.2/run_file_from_search.mp4)

## See also

### Reference

[Run tool window](run-tool-window.html) [Run/debug configurations dialog](run-debug-configurations-dialog.html)

