PhpStorm 2019.1 Help

Run a query

A query is a set of instructions that you use to work with database data. In PhpStorm, you can run a query from the SQL file or a database console.

A database console is an SQL file that is already associated with a data source. It means that you can start running your queries right away.

For SQL files, you need to attach a console first. Attaching a console to the SQL file means that objects will be associated with the data source of this console and queries will be run in the context of this console.

If a file or a console has several statements, you can select whether you want to run all the statements or only an individual statement.

Run an individual statement

  1. Open an SQL file in PhpStorm.

  2. Click the statement that you want to execute.

  3. Press Ctrl+Enter or select Execute from the context menu.

  4. (Optional) If the SQL file is not associated with a console, select the database console in which you want to execute the statement.

  5. In the Statements window, press Enter to run the statement. Otherwise, navigate to another entry to run all statements.

Run a query from the editor

You can open and run an SQL file from the editor. Limitation for the SQL file size is 20 MB. When you open a file that is larger than 20 MB, you see only first 2.5 MB of the file.

Run an SQL file from the editor

  1. Double-click an SQL file to open it in PhpStorm.

  2. Right-click the code in the editor and select Attach Console.

  3. Select a console file that you want to use.

  4. Click the Run icon (Shift+F10).

  5. Select statements that you want to execute and press Enter.

Run existing SQL files

Run a query from a tool window

For example, the Database tool window (View | Tool Windows | Project) displays a list of all available data sources. The Project tool window (View | Tool Windows | Project) includes a list of attached directories, files for extensions (GROOVY scripts), scratch files, and database consoles.

Run an SQL file for one data source

  1. In the Database tool window, right-click a data source.

  2. Select Run SQL Script.

  3. In the Select Path window, navigate to the SQL file that you want to apply.

Run an SQL file

Run an SQL file for several data sources

  1. In the Project tool window, select the necessary SQL file.

  2. Right-click the SQL file, select Run <file_name> (or press Ctrl+Shift+F10).

  3. In the Execution target window, select the necessary data sources.

Run an SQL file for several data sources

Run a query from a database console

When you create a data source, a database console is created automatically. For more information about database consoles, see Database consoles.

Create a database console

To create a console, use one of the following actions in the Database tool window (View | Tool Windows | Database).

  • Click a data source and select File | New | Console.

  • Right-click a data source and select New | Console.

  • Click a data source, press Alt+Insert, and select Console.

  • Click a data source, press Ctrl+Shift+F10, and select New console.

Open a console

  • In the tool window (View | Tool Windows | ), navigate to Scratches and Consoles | Database Consoles | <data_source_name>, double-click a console file.

  • In the Database tool window, click the Jump to console icon (the Jump to console icon ) and select a console.

  • Click a data source, press F4, and select the console that you need.

Open a console

Execute an SQL statement

  1. Place the caret within the statement.

  2. Press Ctrl+Enter. Alternatively, click the Execute icon The Execute icon on the toolbar.

    If you have several statements, select whether you want to execute all statements or a single statement. The suggestion list always contains an item for running all the statements.

Run a query

Save a console as a file

In the console file, press Ctrl+Shift+S. Navigate to the directory where you want to store the file.

Save the console contents as a file
Last modified: 8 July 2019