Executing SQL Statements

From InterBase

Go Up to Interactive Query

Within isql, you can execute SQL statements in either of two ways:

  • Interactively, one statement at a time
  • From a script containing multiple statements

Executing SQL Interactively

To execute a SQL statement interactively:

  1. Type a single SQL statement in the SQL input area. Make sure any other existing statements are commented. A statement is commented if it is preceded by “/*” and followed by “*/”. If the statement already exists in the SQL input area make sure all statements except the one you wish to execute are commented. Commented statements in the SQL input area are ignored during execution.
  2. Choose Query|Execute, enter W+E, or click the Execute toolbar button. If more than one statement is uncommented, Execute executes each statement, one after the other.
Tip:
You can copy text from other Windows applications such as the Notepad and Wordpad text editors and paste it into the SQL input area. You can also copy statements from the isql output area and paste them into the SQL input area. This cut-and-paste method is also a convenient way to use the online SQL tutorial provided in the online Help.

When SQL statements are executed, whether successfully or not, they become part of the isql command history, a sequential list of SQL statements entered in the current session.

Preparing SQL Statements

Use the Prepare toolbar button, or select Query|Prepare, to prepare SQL statements for execution and to view the query plan. Prepare compiles the query plan on the server, and displays it in the Plan tab of the SQL output area. Use Prepare to determine if your SQL script is well-constructed, without having to wait for the SQL script to execute.

Valid SQL Statements

  • You can execute interactively any SQL statement identified as “available in DSQL” in the Language Reference. You cannot use any statements that are specifically identified in the Language Reference as isql statements; all these have functionally equivalent menu items in isql.
For example, the SET NAMES statement cannot be executed from the SQL input area. To change the active character set, choose Edit|Options and select the desired character set option value in the SQL Options dialog.
  • SQL script files can include statements that are not valid to enter interactively. For example, you can use the SET statements such as SET LIST in scripts.
  • Transaction names may not be used with SET TRANSACTION statement.
  • The SQL input area accepts multiple statements, although only one can be executed at a time. Each statement entered in the SQL input area must be terminated by a semicolon (;). The SQL input area accepts multiple statements, although only one can be executed at a time. An uncommented statement that holds the mouse cursor is called the current statement.

Executing a SQL Script File

To execute a SQL script file containing SQL statements:

  1. Choose Query|Load Script or click the Load Script toolbar button.
  2. Locate the desired script file in the Open dialog, and click Open to display the statements of the script file in the SQL input area.
  3. Ensure that you are connected to the desired database.
  4. If you are connected to the database, comment out any CONNECT or CREATE DATABASE statements.
  5. Choose Query|Execute or click Execute on the toolbar to begin executing the entire script statement by statement.
Note:
Statements executed from a loaded script file do not become part of the command history.

Advance To: