SQL$HELP72.HLB  —  ATTACH  Examples
    Example 1: Attaching a database by file name in interactive SQL
    and specifying restricted access

    This interactive SQL statement attaches the database defined by
    the file specification mf_personnel to the current connection,
    and declares the alias pers_alias for that database. Use the SHOW
    DATABASE statement to see the database settings.

    SQL> ATTACH 'ALIAS pers_alias FILENAME mf_personnel -
    cont> RESTRICTED ACCESS';

    Example 2: Attaching a database by path name in interactive SQL

    This interactive SQL statement attaches to the database file name
    extracted from the repository. Use the SHOW DATABASE statement to
    see the database settings.

    SQL> ATTACH
    cont> 'ALIAS PERS PATHNAME DISK3:[REPOSITORY.DEPT2]PERSONNEL';

    Example 3: Using an attach parameter in a program

    This excerpt from an SQL module language procedure shows how you
    might declare a parameter to contain an attach string. You would
    need to compile the module with the PARAMETER COLONS clause in
    order to prefix the parameter with a colon.

    PROCEDURE attach_db
        SQLCODE
        attach_string char(155);

        ATTACH :attach_string;

    You could then write a C program that calls this procedure. The
    line that passes the attach string would need a format such as
    the following:

    main () {
            long sqlcode;

    attach_db( &sqlcode, "ALIAS CORP FILENAME corporate_data" );

    /*      Now dynamic statements can refer to alias CORP        */
    }

    Example 4: Explicitly providing the user name and password in the
    ATTACH statement

    The following example shows how to explicitly provide the user
    name and password in the ATTACH statement.

    SQL> ATTACH 'FILENAME FARSID::USER1:[GREMBOWSKI.DB]MF_PERSONNEL -
    cont>        USER ''grembowski'' USING ''mypassword''';
Close Help