Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements >

CREATE SCHEMA

Use the CREATE SCHEMA statement to issue a block of data definition language (DDL) and GRANT statements as a unit. Use this statement with DB–Access.

Syntax

Read syntax diagramSkip visual syntax diagram>>-CREATE SCHEMA AUTHORIZATION--user---------------------------->
 
   .-------------------------------------------------------------------.
   V                              (1)                                  |
>----+-| CREATE TABLE Statement |------------------------------------+-+-->
     |                           (2)                                 |
     +-| CREATE VIEW Statement |-------------------------------------+
     |                     (3)                                       |
     +-| GRANT Statement |-------------------------------------------+
     |  (4)                              (5)                         |
     '------+-| CREATE INDEX Statement |---------------------------+-'
            |                              (6)                     |
            +-| CREATE SYNONYM Statement |-------------------------+
            |                              (7)                     |
            +-| CREATE TRIGGER Statement |-------------------------+
            |  (8)    (9)                                          |
            '------+--------| CREATE OPTICAL CLUSTER Statement |-+-'
                   |                               (10)          |
                   +-| CREATE SEQUENCE Statement |---------------+
                   |                               (11)          |
                   +-| CREATE ROW TYPE Statement |---------------+
                   |                                  (12)       |
                   +-| CREATE OPAQUE TYPE Statement |------------+
                   |                                    (13)     |
                   +-| CREATE DISTINCT TYPE Statement |----------+
                   |                           (14)              |
                   '-| CREATE CAST Statement |-------------------'
 
>--+---+-------------------------------------------------------><
   '-;-'
 
Notes:
  1. See CREATE TABLE
  2. See CREATE VIEW
  3. See GRANT
  4. Informix extension
  5. See CREATE INDEX
  6. See CREATE SYNONYM
  7. See CREATE TRIGGER
  8. Dynamic Server only
  9. Optical Subsystem only. See the IBM Informix: Optical Subsystem Guide.
  10. See CREATE SEQUENCE
  11. See CREATE ROW TYPE
  12. See CREATE OPAQUE TYPE
  13. See CREATE DISTINCT TYPE
  14. See CREATE CAST
Element Description Restrictions Syntax
user User who owns the database objects that this statement creates If you have DBA privileges, you can specify the name of any user. Otherwise, you must have the Resource privilege, and you must specify your own user name. Owner Name

Usage

The CREATE SCHEMA statement allows the DBA to specify an owner for all database objects that the CREATE SCHEMA statement creates. You cannot issue CREATE SCHEMA until you have created the database that stores the objects.

Users with the Resource privilege can create a schema for themselves. In this case, user must be the name of the person with the Resource privilege who is running the CREATE SCHEMA statement. Anyone with the DBA privilege can also create a schema for someone else. In this case, user can specify a user other than the person who is running the CREATE SCHEMA statement.

You can put CREATE and GRANT statements in any logical order, as the following example shows. Statements are considered part of the CREATE SCHEMA statement until a semicolon ( ; ) or an end-of-file symbol is reached.

CREATE SCHEMA AUTHORIZATION sarah
   CREATE TABLE mytable (mytime DATE, mytext TEXT)
   GRANT SELECT, UPDATE, DELETE ON mytable TO rick
   CREATE VIEW myview AS
      SELECT * FROM mytable WHERE mytime > '12/31/2004'
   CREATE INDEX idxtime ON mytable (mytime); 

Creating Database Objects Within CREATE SCHEMA

All database objects that a CREATE SCHEMA statement creates are owned by user, even if you do not explicitly name each database object. If you are the DBA, you can create database objects for another user. If you are not the DBA, specifying an owner other than yourself results in an error message.

You can only grant privileges with the CREATE SCHEMA statement; you cannot use CREATE SCHEMA to revoke or to drop privileges.

If you create a database object or use the GRANT statement outside a CREATE SCHEMA statement, you receive warnings if you use the -ansi flag or set DBANSIWARN.

Related Information

Related statements: CREATE CAST, CREATE DISTINCT TYPE, CREATE INDEX, CREATE OPAQUE TYPE, CREATE OPCLASS, CREATE ROW TYPE , CREATE SEQUENCE, CREATE SYNONYM , CREATE TABLE , CREATE VIEW , and GRANT

For a discussion of how to create a database, see the IBM Informix Database Design and Implementation Guide.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]