SQL-J Language Reference
Page 50 of 121

SET SCHEMA statement

The SET SCHEMA statement sets the default schema for a connection's session to the designated schema. The default schema is used as the target schema for all statements issued from the connection that do not explicitly specify a schema name.

The target schema must exist for the SET SCHEMA statement to succeed. See CREATE SCHEMA statement.

If the schema is not specified, the default schema is set to the APP schema unless a user name was specified upon connection. If a user name was specified, the user's name is the default schema for the connection if a schema with that name exists. If one does not exist, the user defaults to the APP schema.

The SET SCHEMA statement is not transactional: If the SET SCHEMA statement is part of a transaction that is rolled back, the schema change remains in effect.

Syntax

SET SCHEMA SchemaName

SET SCHEMA Examples

-- Create some objects in the hotel schema
SET SCHEMA hotel

-- Create a table in the hotel schema
CREATE TABLE names (name VARCHAR(20))

-- Move back to the APP schema
SET SCHEMA APP

-- Get data from the hotel schema
SELECT * FROM hotel.names