DB2 schemas and schema qualifiers

The objects in a relational database are organized into sets called schemas. A schema is a collection of named objects that provides a logical classification of objects in the database. The first part of a schema name is the qualifier.

A schema provides a logical classification of objects in the database. The objects that a schema can contain include tables, indexes, table spaces, distinct types, functions, stored procedures, and triggers. An object is assigned to a schema when it is created.

The schema name of the object determines the schema to which the object belongs. A user object, such as a distinct type, function, procedure, sequence, or trigger should not be created in a system schema, which is any one of a set of schemas that are reserved for use by the DB2® subsystem.

When a table, index, table space, distinct type, function, stored procedure, or trigger is created, it is given a qualified two-part name. The first part is the schema name (or the qualifier), which is either implicitly or explicitly specified. The default schema is the authorization ID of the owner of the plan or package. The second part is the name of the object.

In previous versions, CREATE statements had certain restrictions when the value of CURRENT SCHEMA was different from CURRENT SQLID value. Although those restrictions no longer exist, you now must consider how to determine the qualifier and owner when CURRENT SCHEMA and CURRENT SQLID contain different values. The rules for how the owner is determined depend on the type of object being created.

CURRENT SCHEMA and CURRENT SQLID affect only dynamic SQL statements. Static CREATE statements are not affected by either CURRENT SCHEMA or CURRENT SQLID.

The following table summarizes the effect of CURRENT SCHEMA in determining the schema qualifier and owner for these objects:

  • Alias
  • Auxiliary table
  • Created global temporary table
  • Table
  • View
Table 1. Schema qualifier and owner for objects
Specification of name for new object being created Schema qualifier of new object Owner of new object
name (no qualifier) value of CURRENT SCHEMA value of CURRENT SQLID
abc.name (single qualifier) abc abc
......abc.name (multiple qualifiers) abc abc

The following table summarizes the effect of CURRENT SCHEMA in determining the schema qualifier and owner for these objects:

  • User-defined distinct type
  • User-defined function
  • Procedure
  • Sequence
  • Trigger
Table 2. Schema qualifier and owner for additional objects
Specification of name for new object being created Schema qualifier of new object Owner of new object
name (no qualifier) value of CURRENT SCHEMA value of CURRENT SQLID
abc.name (single qualifier) abc value of CURRENT SQLID
......abc.name (multiple qualifiers) abc value of CURRENT SQLID