SET SCHEMA

Use the SET SCHEMA command to change to a different schema. If you specify db_name.schema_name to connect to a schema in a different database, the command issues a SET CATALOG command to change to the database. You cannot use the SET SCHEMA command to change to a schema in a different database within the body of a stored procedure or inside an explicit transaction (BEGIN/COMMIT pair).

Syntax

Syntax for connecting to a different schema.
SET SCHEMA [<database_name>.]<schema_name>

Inputs

The SET SCHEMA command takes the following inputs:

Table 1. SET SCHEMA inputs
Input Description
<database_name> The name of the database that contains the schema to which you want to change. The default is the current database.
<schema_name> The schema to which you want to change.

Output

The SET SCHEMA command has the following output:

Table 2. SET SCHEMA output
Output Description
SET SCHEMA The command was successful.
ERROR: SET SCHEMA: object <name> does not exist. The schema does not exist.

Privileges

You must be an administrator or you must have the List privilege for the schema. If the schema resides in a different database, you must have the List privilege to change to that database.

Usage

The following provides sample usage.
MYDB.SCH1(USER)=> SET SCHEMA schema1;
SET SCHEMA
MYDB.SCHEMA1(USER)=>

watsonx.data considerations

If there are schema names in Hive Metastore that are NPS keywords, you cannot use those keywords as identifiers when using the schema. For more information, see Schema names in Hive Metastore (HMS) that are NPS reserved keywords.