Running SQL commands from files

The SQL interactive interface accepts SQL files that can contain several SQL commands. You can also use the interface to redirect text files. Both functions are useful when you must perform repetitive administration tasks.

Before you begin

SQL files for use with the SQL interactive interface must contain only SQL commands and must end with the go command.

nco_sql does not allow whitespace before the go keyword. For example, if you use white space to indent the commands in a file, the commands fail.

Procedure

Running commands from a file.

  • To read in a file when you are starting the interface, use the following command:

    For Linux operating systemFor UNIX operating system$NCHOME/omnibus/bin/nco_sql -server ObjectServer_name -username user_name -password password < file_name.txt

    For Windows operating system%NCHOME%\omnibus\bin\isql -S ObjectServer_name -U user_name -P password -i file_name.txt

Redirecting output to a file.

  • To redirect output to a file when you are starting the interface, use the following command:

    For Linux operating systemFor UNIX operating system$NCHOME/omnibus/bin/nco_sql -server ObjectServer_name -username user_name -password password < input_file.txt > output_file.txt

    For Windows operating system%NCHOME%\omnibus\bin\isql -S ObjectServer_name -U user_name -P password -i input_file.txt -o output_file.txt

    Note: Do not use the standard < and > redirection characters on Windows operating systems.

Reading in a file when the interface is running.

  • When the interface is running, enter the following command at the beginning of a new line:

    :r file_name

    Do not include the go command in the file. Instead, enter the go command at the beginning of a new line.

Results

If the SQL commands in the file are valid, the changes are implemented in the ObjectServer.