Previous Topic: Executing SQL Data Description StatementsNext Topic: Creating a Table


Creating a Schema

You create a schema by issuing a CREATE SCHEMA statement.

Things You Can Specify

  1. Schema name
  2. Optionally a default area
  3. Optionally a reference to another schema, either an SQL or non-SQL schema

Considerations

Examples

In the following example, the schema PROD is defined. The default area for the schema is PROD_AREA. Rows in tables associated with this schema will be stored in PROD_AREA unless an area name is explicitly coded in the CREATE TABLE statement.

create schema prod
   default area prod_area;

In the following example, the schema WINDOW is defined and associated with the non-SQL defined schema SCHED. Programs using SQL data manipulation language statements can access data in the non-SQL database by using the schema WINDOW.

create schema window
    for nonsql schema sched;

In the following example, the schemas HRTEST1 and HRTEST2 are defined as referencing schemas for SQL schema HRTEST0. References to tables in HRTEST1 will access data in the HRTEST1 database while those in HRTEST2 will access data in the HRTEST2 database. These databases contain identically-defined base tables as described by the HRTEST0 schema.

create schema hrtest1
   for sql schema hrtest0 dbname hrtest1;

create schema hrtest2
   for sql schema hrtest0 dbname hrtest2;

In the following example, the schema HRTEST is also defined as a referencing schema for SQL schema HRTEST0; however, HRTEST is not associated with any specific database instance. Consequently, the data that is accessed through references to HRTEST tables will be determined at runtime by the database to which the SQL session connects.

create schema hrtest
   for sql schema hrtest0;