Importing SQL statements to scripts in the SQL and XQuery editor

When you are working with an SQL script in the SQL and XQuery editor, you can import SQL statements from a file to the script.

Before you begin

About this task

The script that is open in the editor can be empty or can contain one or more existing SQL statements. You can import SQL statements from multiple files to the same script in separate passes.

If you import SQL statements to a script that already contains SQL statements, the imported SQL statements are bracketed with BEGIN and END comment lines. An additional Script comment line describes the path to the file that contains the imported SQL statements.

The following code shows an example of a script in the SQL and XQuery editor with SQL statements that were imported from three files. At the beginning of the process, the script was empty.
  • The CREATE TABLE, INSERT INTO, and SELECT statements for table t1 were imported in the first pass.
  • The statements in the sample2.sql file were imported in the second pass.
  • The statements in the sample3.sql file were imported in the third pass.
CREATE TABLE t1 (c1 char
                 c2 char(20)
                 c3 char(30) );

INSERT INTO t1 VALUES "a", "a", "g");

SELECT * FROM t1;

--  BEGIN  imported SQL statements
--  Script:  C:\Documents and Settings\userID\Desktop\scripts\sample2.sql
CREATE TABLE t2 (c1 char
                 c2 char(20)
                 c3 char(30) );

INSERT INTO t2 values "b", "b", "h");
--  END  imported SQL statements

--  BEGIN  imported SQL statements
--  Script:  C:\Documents and Settings\userID\Desktop\scripts\sample3.sql
CREATE TABLE t3 (c1 char
                 c2 char(20)
                 c3 char(30) );

INSERT INTO t3 values "c", "c", "i");
--  END  imported SQL statements

Procedure

To import SQL statements to a script in the SQL and XQuery editor:

  1. If the script already contains SQL statements, move the insertion point to the place in the script where you want to import the SQL statements. The editor does not validate the insertion point.
  2. In the top border of the editor, click Import.
  3. In the Import from Directory window, select the file that contains the SQL statements that you want to import.
  4. Open the Validation tab and specify a statement terminator.

Results

The SQL statements in the file that you select are added to the script at the insertion point. If you make changes to SQL statements in the file that you imported, the imported statements in the script are not updated with those changes.

Feedback