Running a SQL Script
Go Up to Using SQL Scripts
The following steps execute all the SQL statements in the specified script file. The contents of the script are not displayed in the SQL input area.
To Run a SQL Script Using IBConsole
- If you are not already in the SQL window, click the Launch SQL toolbar button or choose Tools|Interactive SQL.
- If you are not running the SQL script on the database to which you are currently connected, then check that the file begins with a valid, uncommented,
CONNECT
orCREATE DATABASE
statement. - Choose Query|Load Script.
- Enter or locate the desired script filename in the Open dialog, and click Open to load the script into the SQL input area.
- Click the Execute toolbar button, or choose Query|Execute.
If IBConsole encounters an error, an information dialog appears indicating the error. Once IBConsole finishes executing the script, the script results are displayed in the SQL output window.
After a script executes, all isql
session settings prior to executing the script are restored as well as the previous database connection, if any. In other words, any isql
SET
commands in the script affect only the isql
session while the script is running.
To Run a SQL Script Using the Command-line isql Tool
You can run a script from any console prompt using the -input
option to isql. Specify the full path and filename. In the following example, the script does not contain a CREATE DATABASE
statement; it runs against an existing database:
isql database_name -input filename
The following example runs a script that creates a database:
isql -input filename
During an active isql
session in which you are already connected to a database, you use the INPUT
command to read and execute a SQL script against that database:
SQL> INPUT filename
See Invoking isql for more about running isql
.