DataGrip 2019.3 Help

SQL statements

Execute statements in a database console

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

  1. In the Database tool window (View | Tool Windows | Database), click the data source.

  2. Open F4 or create (Ctrl+Shift+F10 | New Console) a database console. For more information about working with consoles, see Working with consoles.

  3. Type or paste the statement that you want to execute.

  4. 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.

Executing parameterized statements

If you have parameters in your statement, you must specify the values of the parameters before you execute the statement.

To execute a parameterized statement, click the Execute button the Execute button on the toolbar and enter values in the second column. Alternatively, to open the Parameters dialog, click the View Parameters button the View Parameters button.

Execute a parametrized statement

Execute a group of statements

  • To execute a group of statements, select the necessary statements and click the Execute button the Execute button.

    Execute a group of statements

Execute all statements in a console

  • To execute all the statements in a console, use the Run '<console_name>' command (as an alternative to the Execute command).

  • Right-click the console tab or any area in the console and select Run '<console_name>'.

    The Run '<console_name>' command has the following restrictions:

    • Statements with parameters are skipped.

    • Retrieved data for the SELECT statements are not shown.

    Execute all statements in a console

Execute a part of a statement

  • To execute a part of a statement (for example, a subquery), select the fragment that you want to execute and click the Execute button the Execute button.

    Execute a part of a statement

View history of executed statements

DataGrip stores history of all statements that you have run.

To open the History dialog, click the History button or press Ctrl+Alt+E.

  • To filter information, start typing your search query.

  • To paste the query from the History dialog to the console, double-click the query in the left pane of the History dialog.

  • To delete a record from history, select the record and press Delete.

View history of executed queries

Stop running statements

To terminate execution of the current statement or statements, click the Disconnect button the Disconnect button or press Ctrl+F2.

Terminate statement execution

Save the result of a SELECT statement into a file

  1. Right-click a SELECT statement.

  2. Select Execute to File and select the output format.

  3. Specify the file location and name.

    Save the result of a SELECT statement into a file

Edit data in INSERT statements as a table

  1. Select INSERT statements that you want to edit.

  2. Right-click the selection and click Edit as Table.

    Edit data in INSERT statements as a table

Run stored procedures

A stored procedure is a set of SQL statements with an assigned name. You can execute stored procedures in PostgreSQL, Microsoft SQL Server, Oracle, and MySQL.

  1. Right-click a stored function that you want to execute.

  2. In the Execute Routine window, type all the necessary parameter values, and click OK.

    Run stored procedures

Enable output from the DBMS_OUTPUT package (Oracle)

In Oracle, the DBMS_OUTPUT package enables you to send messages from stored procedures, packages, and triggers. You can enable or disable showing the contents of the DBMS_OUTPUT buffer in the output pane.

  • To toggle the DBMS_OUTPUT option, click the Enable SYS.DBMS_OUTPUT button the Enable SYS.DBMS_OUTPUT button on the toolbar of the Services tool window.

Last modified: 13 April 2020