The CREATE SCHEMA statement defines a collection and optionally creates tables, views, aliases, indexes, and distinct types. Comments and labels may be added in the catalog description of tables, views, aliases, indexes, columns, and distinct types. Table, view, and distinct type privileges can be granted to users.
This statement can only be issued using the RUNSQLSTM command.
The privileges held by the authorization ID of the statement must include at least one of the following:
If the AUTHORIZATION clause is specified, the privileges held by the authorization ID of the statement must also include at least one of the following:
>>-CREATE SCHEMA----+-collection-name--------------------+------>
'-AUTHORIZATION--authorization-name--'
>-----+------------------+---+----------------------+----------->
'-IN ASP--integer--' '-WITH DATA DICTIONARY-'
>-----+------------------------------------------------------------+>
| .------------------------------------------------------. |
| V | |
'-----+-COMMENT ON statement---------------------------+--+--'
+-CREATE ALIAS statement-------------------------+
+-CREATE DISTINCT TYPE statement-----------------+
+-CREATE INDEX statement-------------------------+
+-CREATE TABLE statement-------------------------+
+-CREATE VIEW statement--------------------------+
+-GRANT (Table Privileges) statement-------------+
+-GRANT (User-Defined Type Privileges) statement-+
| (1) |
'-LABEL ON statement-----------------------------'
>--------------------------------------------------------------><
Notes:
If a CREATE TABLE, CREATE INDEX, CREATE ALIAS, CREATE DISTINCT TYPE, or CREATE VIEW statement contains a qualified name for the table, index, alias, distinct type, or view being created, the collection name specified in that qualified name must be the same as the name of the collection being created. Any other table or view names referenced within the schema definition may be qualified by any collection name. Unqualified table, index, alias, distinct type, or view names in any SQL statement are implicitly qualified with the name of the created collection. The maximum length of any individual CREATE TABLE, CREATE INDEX, CREATE DISTINCT TYPE, CREATE VIEW, COMMENT ON, LABEL ON, or GRANT statements within the CREATE SCHEMA statement is 32766.
Delimiters are not used between the SQL statements.
The owner of the created objects is determined as follows:
Create a collection that has an inventory part table and an index over the part number. Give authority to the schema to the user profile JONES.
CREATE SCHEMA INVENTORY
CREATE TABLE PART (PARTNO SMALLINT NOT NULL,
DESCR VARCHAR(24),
QUANTITY INT)
CREATE INDEX PARTIND ON PART (PARTNO)
GRANT ALL ON PART TO JONES
Create a collection using the authorization ID of SMITH. Create a student table that has a comment on the student number column.
CREATE SCHEMA AUTHORIZATION SMITH
CREATE TABLE SMITH.STUDENT (STUDNBR SMALLINT NOT NULL UNIQUE,
LASTNAME CHAR(20),
FIRSTNAME CHAR(20),
ADDRESS CHAR(50))
COMMENT ON STUDENT (STUDNBR IS 'THIS IS A UNIQUE ID#')