The SET SCHEMA statement changes the value of the CURRENT SCHEMA special register.
This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared.
No authorization is required to execute this statement.
.-CURRENT-. .-=-. >>-SET--+-+---------+--SCHEMA-+--+---+--------------------------> '-CURRENT_SCHEMA------' >----+-schema-name------+-------------------------------------->< +-+-SESSION_USER-+-+ | '-USER---------' | +-SYSTEM_USER------+ +-variable---------+ +-string-constant--+ '-DEFAULT----------'
If the value specified does not conform to the rules for a schema-name, an error is returned.
The variable:
Considerations for keywords: There is a difference between specifying a single keyword (such as USER) as a single keyword or as a delimited identifier. To indicate that the current value of the USER special register should be used for setting the current schema, specify USER as a keyword. If USER is specified as a delimited identifier instead (for example, "USER"), it is interpreted as a schema name of that value ("USER").
Transaction considerations: The SET SCHEMA statement is not a commitable operation. ROLLBACK has no effect on the CURRENT SCHEMA.
Impact on other special registers: Setting the CURRENT SCHEMA special register does not effect the CURRENT PATH special register. Hence, the CURRENT SCHEMA will not be included in the SQL path and functions, procedures and user-defined type resolution may not find these objects. To include the current schema value in the SQL path, whenever the SET SCHEMA statement is issued, also issue the SET PATH statement including the schema name from the SET SCHEMA statement.
CURRENT SCHEMA: The value of the CURRENT SCHEMA special register is used as the qualifier for all unqualified names in all dynamic SQL statements except in programs where the DYNDFTCOL has been specified. If DYNDFTCOL is specified in a program, its schema name is used instead of the CURRENT SCHEMA schema name.
For SQL naming, the initial value of the CURRENT SCHEMA special register is equivalent to USER. For system naming, the initial value of the CURRENT SCHEMA special register is '*LIBL'.
Syntax alternatives: CURRENT SQLID is accepted as a synonym for CURRENT SCHEMA and the effect of a SET CURRENT SQLID statement will be identical to that of a SET CURRENT SCHEMA statement. No other effects, such as statement authorization changes, will occur.
SET SCHEMA is equivalent to calling the QSQCHGDC API.
Example 1: The following statement sets the CURRENT SCHEMA special register.
SET SCHEMA = RICK
Example 2: The following example retrieves the current value of the CURRENT SCHEMA special register into the host variable called CURSCHEMA.
EXEC SQL VALUES(CURRENT SCHEMA) INTO :CURSCHEMA
The value would be RICK, set by the previous example.