SET SCHEMA

The SET SCHEMA statement changes the value of the CURRENT SCHEMA special register.

Invocation

This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared.

Authorization

No authorization is required to execute this statement.

Syntax

Click to skip syntax diagram
Read syntax diagramSkip visual syntax diagram          .-CURRENT-.            .-=-.
>>-SET--+-+---------+--SCHEMA-+--+---+-------------------------->
        '-CURRENT_SCHEMA------'
 
>----+-schema-name------+--------------------------------------><
     +-+-SESSION_USER-+-+
     | '-USER---------' |
     +-SYSTEM_USER------+
     +-variable---------+
     +-string-constant--+
     '-DEFAULT----------'
 

Description

schema-name
Identifies a schema. No validation that the schema exists is made at the time the CURRENT SCHEMA is set.

If the value specified does not conform to the rules for a schema-name, an error is returned.

SESSION_USER or USER
This value is the SESSION_USER special register.
SYSTEM_USER
This value is the SYSTEM_USER special register.
variable
Specifies a variable which contains a schema name. The content is not folded to uppercase.

The variable:

string-constant
A character or UCS-2 constant with a schema name.
DEFAULT
The CURRENT SCHEMA is set to its initial value. The initial value for SQL naming is USER. The initial value for system naming is *LIBL.

Notes

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.

Examples

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.



[ Top of Page | Previous Page | Next Page | Contents | Index ]