SQL/MX 2.x Reference Manual (H06.04+)

Embedded-Only SQL/MX Statements
HP NonStop SQL/MX Reference Manual540440-003
3-32
DECLARE SCHEMA Declaration
DECLARE SCHEMA Declaration
The DECLARE SCHEMA declaration is a compiler directive that sets the default
schema (and optionally, the catalog) for unqualified object names in static SQL
statements that follow the declaration within a compilation unit. The DECLARE
CATALOG declaration also sets the default catalog. See DECLARE CATALOG
Declaration on page 3-21.
DECLARE SCHEMA is an SQL/MX extension that you use only in embedded SQL
programs.
default-schema
is a character string literal enclosed in single quotation marks (') that specifies the
default schema (and optionally the catalog). Examples are 'sales' for only a
default schema or 'samdbcat.sales' for both a default schema and catalog.
Considerations for DECLARE SCHEMA
Scope of DECLARE SCHEMA
You can specify more than one directive in an embedded SQL program. Each directive
replaces the preceding directive and stays in effect until it is replaced by another
directive or until the end of the program’s compilation unit is reached.
If no DECLARE SCHEMA declaration is in effect when the SQL/MX compiler
encounters an unqualified object name, the compiler uses the SCHEMA attribute as
determined by NonStop SQL/MX. For more information, see Object Naming on
page 10-48 and the SQL/MX Programming Manual for C and COBOL.
C Examples of DECLARE SCHEMA
Set the default catalog and schema:
EXEC SQL DECLARE CATALOG 'SAMDBCAT';
EXEC SQL DECLARE SCHEMA 'SALES';
Set the default catalog and schema within one statement:
EXEC SQL DECLARE SCHEMA 'SAMDBCAT.SALES';
COBOL Examples of DECLARE SCHEMA
Set the default catalog and schema:
EXEC SQL DECLARE CATALOG 'SAMDBCAT' END-EXEC.
EXEC SQL DECLARE SCHEMA 'SALES' END-EXEC.
DECLARE SCHEMA default-schema