Running SQL statements

You can run and test SQL statements that you create.

About this task

Important: When you run an INSERT, UPDATE, or DELETE statement, you can modify the database.

If an SQL statement contains host variables, you are prompted to substitute a value of the appropriate type for each host variable.

Restriction:
  • You cannot run a statement that is in an SQL Statements folder of a physical data model by using the statement's pop-up menu in the Data Project Explorer.

Procedure

To run an SQL statement:

  1. Click a command or a toolbar button to start running the SQL statement:
    In the Data Project Explorer view
    • In the SQL Scripts folder of a data project, right-click an SQL statement, and then click Run SQL on the pop-up menu.
    When the SQL statement is open in the SQL Query Builder
    • Click Run > Run SQL.
    • Click SQL > Run SQL.
    • Right-click in the SQL Source pane of the SQL Query Builder, and then click Run SQL on the pop-up menu.
    • On the main toolbar, click Run the SQL Statement.
    When the SQL statement is open in the SQL and XQuery editor
    • In the top border of the editor, click Run SQL.
    • Click Run > Run SQL.
    • Right-click in the SQL and XQuery editor, and then click Run SQL on the pop-up menu.
  2. If you are running an SQL statement in a data design project, select a database connection in the Connection Selection wizard, and then click Finish. If the Finish button is not available, click Reconnect.
  3. If you are not connected to your database, specify your password in the Database Authorization window, and then click OK.
  4. If the statement contains one or more host variables, specify values in the Specify Variable Values window:
    1. In each row of the table that contains a host variable, double-click the cell under the Value heading, and then enter a value for the host variable.
    2. Click Finish.

Results

The results are displayed in the SQL Results view. It opens automatically if it is not already open.

What to do next

If you have a connection to a database in this product and that connection is cancelled in some way from outside the workbench (for example, in DB2® by using the "force applications all" command), the fact that the connection has been dropped cannot be detected.

Some tasks that you perform depend on an active connection to your database. Any task that requires an active connection to the database (such as running an SQL statement in the SQL Query Builder) does not work properly if the connection is dropped. To work around this problem, you must reconnect to the database.


Feedback