ibm-information-center/dist/eclipse/plugins/i5OS.ic.db2_5.4.0.1/rbafzmstxcschema.htm

263 lines
16 KiB
HTML
Raw Normal View History

2024-04-02 14:02:31 +00:00
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="dc.language" scheme="rfc1766" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<meta name="dc.date" scheme="iso8601" content="2005-09-19" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow"/>
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="keywords" content="CREATE SCHEMA statement, CREATE SCHEMA,
SQL statements, in CREATE SCHEMA statement, schema-name, authorization-name,
IN ASP clause, WITH DATA DICTIONARY clause, DATA DICTIONARY clause" />
<title>CREATE SCHEMA</title>
<link rel="stylesheet" type="text/css" href="ibmidwb.css" />
<link rel="stylesheet" type="text/css" href="ic.css" />
</head>
<body>
<a id="Top_Of_Page" name="Top_Of_Page"></a><!-- Java sync-link -->
<script language = "Javascript" src = "../rzahg/synch.js" type="text/javascript"></script>
<a name="xcschema"></a>
<h2 id="xcschema"><a href="rbafzmst02.htm#ToC_911">CREATE SCHEMA</a></h2><a id="idx2025" name="idx2025"></a><a id="idx2026" name="idx2026"></a>
<p>The CREATE SCHEMA statement defines a schema at the current server 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.</p>
<a name="wq1285"></a>
<h3 id="wq1285"><a href="rbafzmst02.htm#ToC_912">Invocation</a></h3>
<p>This statement can be embedded in an application program or issued interactively.
It is an executable statement that can be dynamically prepared.</p>
<a name="wq1286"></a>
<h3 id="wq1286"><a href="rbafzmst02.htm#ToC_913">Authorization</a></h3>
<p>The privileges held by the authorization ID of the statement must include
at least one of the following: </p>
<ul>
<li>The *USE system authority to the following CL commands:
<ul>
<li>Create Library (CRTLIB)</li>
<li>If WITH DATA DICTIONARY is specified, Create Data Dictionary (CRTDTADCT)</li></ul></li>
<li>Administrative authority</li></ul>
<p>The privileges held by the authorization ID of the statement must include
at least one of the following: </p>
<ul>
<li>The privileges defined for each SQL statement included in the CREATE SCHEMA
statement</li>
<li>Administrative authority</li></ul>
<p>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: </p>
<ul>
<li>The system authority *ADD to the user profile identified by authorization-name</li>
<li>Administrative authority</li></ul>
<a name="wq1287"></a>
<h3 id="wq1287"><a href="rbafzmst02.htm#ToC_914">Syntax</a></h3>
<a href="rbafzmstxcschema.htm#synscrtschema"><img src="c.gif" alt="Click to skip syntax diagram" /></a>
<pre class="cgraphic"><span><img src="c.gif" alt="Read syntax diagram" longdesc="rbafzmstsyn300.htm"
border="0" /></span><a href="#skipsyn-299"><img src="c.gif" alt="Skip visual syntax diagram"
border="0" /></a>>>-CREATE SCHEMA--+-<span class="italic">schema-name</span>-----------------------+--------->
'-AUTHORIZATION--<span class="italic">authorization-name</span>-'
>--+----------------------+------------------------------------->
'-IN ASP--+-<span class="italic">integer</span>--+-'
'-<span class="italic">ASP-name</span>-'
>--+----------------------------------------------------+------>&lt;
| .------------------------------------------------. |
| V | |
'---+-<span class="italic">COMMENT statement</span>--------------------------+-+-'
+-<span class="italic">CREATE ALIAS statement</span>---------------------+
+-<span class="italic">CREATE DISTINCT TYPE statement</span>-------------+
+-<span class="italic">CREATE INDEX statement</span>---------------------+
+-<span class="italic">CREATE SEQUENCE statement</span>------------------+
+-<span class="italic">CREATE TABLE statement</span>---------------------+
+-<span class="italic">CREATE VIEW statement</span>----------------------+
+-<span class="italic">GRANT (Distinct Type Privileges) statement</span>-+
+-<span class="italic">GRANT (Sequence Privileges) statement</span>------+
+-<span class="italic">GRANT (Table Privileges) statement</span>---------+
| (1) |
'-<span class="italic">LABEL statement</span>----------------------------'
</pre>
<a name="skipsyn-299" id="skipsyn-299"></a>
<a name="wq1288"></a>
<div class="notelisttitle" id="wq1288">Notes:</div>
<ol type="1">
<li>Labels and comments on packages, procedures, functions, and parameters
are not supported in the CREATE SCHEMA statement.</li>
</ol>
<a name="synscrtschema"></a>
<h3 id="synscrtschema"><a href="rbafzmst02.htm#ToC_915">Description</a></h3>
<dl class="parml">
<dt class="bold"><var class="pv">schema-name</var> <a id="idx2027" name="idx2027"></a></dt>
<dd>Names the schema. A schema is created using this name. If
schema-name is specified, the authorization ID of the statement is the run-time
authorization ID. The name must not be the same as the name of an existing
schema at the current server.
</dd>
<dt class="bold"><var class="pv">authorization-name</var> <a id="idx2028" name="idx2028"></a></dt>
<dd>Identifies the authorization ID of the statement. This authorization
name is also the schema-name. The name must not be the same as the name of
an existing schema at the current server.
</dd>
<dt class="bold">IN ASP <var class="pv">integer</var> </dt><a id="idx2029" name="idx2029"></a>
<dd>Specifies the auxiliary storage pool (ASP) in which to create the schema.
The integer must be between 1 and 32. If 1 is specified, the schema is created
on the system ASP. If this clause is omitted, an ASP of 1 is assumed.
</dd>
<dt class="bold">IN ASP <var class="pv">ASP-name</var> </dt>
<dd>Specifies the auxiliary storage pool (ASP) in which to create the schema.
The name must identify an auxiliary stroage pool that exists at the current
server.
</dd>
<dt class="bold">COMMENT statement</dt>
<dd>Adds or replaces comments in the catalog descriptions of tables, views,
sequences, or columns. Comments on packages are not allowed. See the COMMENT
statement <a href="rbafzmstcomnt.htm#xcomnt">COMMENT</a>.
</dd>
<dt class="bold">CREATE ALIAS statement</dt>
<dd>Creates an alias into the schema. See the CREATE ALIAS statement <a href="rbafzmsthcalias.htm#hcalias">CREATE ALIAS</a>.
</dd>
<dt class="bold">CREATE DISTINCT TYPE statement</dt>
<dd>Creates a user-defined distinct type into the schema. See the CREATE
DISTINCT TYPE statement <a href="rbafzmstcrtudt.htm#crtudt">CREATE DISTINCT TYPE</a>.
</dd>
<dt class="bold">CREATE INDEX statement</dt>
<dd>Creates an index into the schema. See the CREATE INDEX statement <a href="rbafzmstxcindx.htm#xcindx">CREATE INDEX</a>.
</dd>
<dt class="bold">CREATE SEQUENCE statement</dt>
<dd>Creates a sequence into the schema. See the CREATE SEQUENCE statement <a href="rbafzmstcsequence.htm#csequence">CREATE SEQUENCE</a>.
</dd>
<dt class="bold">CREATE TABLE statement</dt>
<dd>Creates a table into the schema. See the CREATE TABLE statement <a href="rbafzmsthctabl.htm#hctabl">CREATE TABLE</a>.
</dd>
<dt class="bold">CREATE VIEW statement</dt>
<dd>Creates a view into the schema. See the CREATE VIEW statement <a href="rbafzmsthcview.htm#hcview">CREATE VIEW</a>.
</dd>
<dt class="bold">GRANT (Distinct Type Privileges) statement</dt>
<dd>Grants privileges for distinct types in the schema. See the GRANT statement <a href="rbafzmstgntudtp.htm#gntudtp">GRANT (Distinct Type Privileges)</a>.
</dd>
<dt class="bold">GRANT (Sequence Privileges) statement</dt>
<dd>Grants privileges for sequences in the schema. See the GRANT statement <a href="rbafzmstgntseqp.htm#gntseqp">GRANT (Sequence Privileges)</a>.
</dd>
<dt class="bold">GRANT (Table Privileges) statement</dt>
<dd>Grants privileges for tables and views in the schema. See the GRANT
statement <a href="rbafzmstgnt.htm#gnt">GRANT (Table or View Privileges)</a>.
</dd>
<dt class="bold">LABEL statement</dt>
<dd>Adds or replaces labels in the catalog descriptions of tables, views,
sequences, or columns in the schema. Labels on packages are not allowed. See
the LABEL statement<a href="rbafzmstlabelon.htm#labelon">LABEL</a>.
</dd>
</dl>
<a name="wq1290"></a>
<h3 id="wq1290"><a href="rbafzmst02.htm#ToC_916">Notes</a></h3>
<p><span class="bold">Schema attributes:</span> A schema is created as: </p>
<ul>
<li>A library: A library groups related objects, and allows you to find objects
by name.</li>
<li>A catalog: A catalog contains descriptions of the tables, views, indexes,
and packages in the schema. A catalog consists of a set of views. For more
information, see the <a href="../sqlp/rbafykickoff.htm">SQL Programming </a> book.</li>
<li>A journal and journal receiver: A journal QSQJRN and journal receiver
QSQJRN0001 is created in the schema, and is used to record changes to all
tables subsequently created in the schema. For more information, see the <a href="../rzaki/rzakikickoff.htm">Journal Management</a> topic in the iSeries&trade; Information
Center.</li></ul>
<p>An index created over a distributed table is created on all of the servers
across which the table is distributed. For more information about distributed
tables, see the <a href="../dbmult/rzaf3kickoff.htm">DB2&reg; Multisystem</a> book.</p>
<p><span class="bold">Object ownership:</span> The owner of the schema
and created objects is determined as follows: </p>
<ul>
<li>If an AUTHORIZATION clause is specified, the specified authorization ID
owns the schema and all objects created by the statement.</li>
<li>If an AUTHORIZATION clause is not specified and SQL names are specified:
<ul>
<li>If a user profile with the same name as the schema exists, the <span class="italic">owner</span> of the schema and all objects created by the statement is that
user profile.</li>
<li>Otherwise, the <span class="italic">owner</span> of the schema and all objects
created by the statement is the user profile or group user profile of the
job executing the statement.</li></ul></li>
<li>Otherwise, the <span class="italic">owner</span> of the schema and all objects
created by the statement is the user profile or the group user profile of
the job executing the statement.</li></ul>
<p><span class="bold">Object authority:</span> If SQL names are used, the schema
and any other objects are created with the system authority of *EXCLUDE on
*PUBLIC and the library is created with the create authority parameter CRTAUT(*EXCLUDE).
The owner is the only user having any authority to the schema. If other users
require authority to the schema, the owner can grant authority to the objects
created; using the CL command Grant Object Authority (GRTOBJAUT).</p>
<p>If system names are used, the schema and any other objects are created
with the system authority given to *PUBLIC is determined by the system value
QCRTAUT, and the library is created with CRTAUT(*SYSVAL). For more information
about system security, see the books <a href="../books/sc415302.pdf" target="_blank">iSeries Security
Reference</a>
<img src="wbpdf.gif" alt="Link to PDF" />, and the <a href="../sqlp/rbafykickoff.htm">SQL Programming</a> book.</p>
<p>If the owner of the schema is a member of a group profile (GRPPRF keyword)
and group authority is specified (GRPAUT keyword), that group profile will
also have authority to the schema.</p>
<p><span class="bold">Object names:</span> If a CREATE TABLE, CREATE INDEX, CREATE
ALIAS, CREATE DISTINCT TYPE, CREATE SEQUENCE, or CREATE VIEW statement contains
a qualified name for the table, index, alias, distinct type, sequence, or
view being created, the schema name specified in that qualified name must
be the same as the name of the schema being created. Any other object names
referenced within the schema definition may be qualified by any schema name.
Unqualified table, index, alias, distinct type, sequence, or view names in
any SQL statement are implicitly qualified with the name of the created schema.</p>
<p>Delimiters are not used between the SQL statements.</p>
<p><span class="bold">SQL statement length:</span> If the CREATE SCHEMA
statement is executed via the RUNSQLSTM command, the maximum length of any
individual CREATE TABLE, CREATE INDEX, CREATE DISTINCT TYPE, CREATE ALIAS,
CREATE SEQUENCE, CREATE VIEW, COMMENT, LABEL, or GRANT statements within the
CREATE SCHEMA statement is 2 097 152. Otherwise, the entire CREATE SCHEMA
statement is limited to 2 097 152.</p>
<p><span class="bold">Syntax alternatives:</span> The COLLECTION keyword can be
used as a synonym for SCHEMA for compatibility to prior releases. This keyword
is non-standard and should not be used.</p><a id="idx2030" name="idx2030"></a><a id="idx2031" name="idx2031"></a>
<p><span class="bold">Deprecated features:</span> The WITH DATA DICTIONARY
clause causes an IDDU data dictionary to be created in the schema. While the
clause can still be specified at the end of the CREATE SCHEMA statement and
is still supported; it is not recommended.</p>
<p>A schema created with a data dictionary cannot contain tables with LOB
or DATALINK columns. The clause has no effect on the creation of catalog views.</p>
<a name="wq1291"></a>
<h3 id="wq1291"><a href="rbafzmst02.htm#ToC_917">Examples</a></h3>
<p><span class="italic">Example 1:</span> Create a schema that has an inventory
part table and an index over the part number. Give authority to the schema
to the user profile JONES. </p>
<pre class="xmp"> <span class="bold">CREATE SCHEMA</span> INVENTORY
<span class="bold">CREATE TABLE</span> PART (PARTNO <span class="bold">SMALLINT NOT NULL</span>,
DESCR <span class="bold">VARCHAR</span>(24),
QUANTITY <span class="bold">INT</span>)
<span class="bold">CREATE INDEX</span> PARTIND <span class="bold">ON</span> PART (PARTNO)
<span class="bold">GRANT ALL ON</span> PART <span class="bold">TO</span> JONES</pre>
<p><span class="italic">Example 2:</span> Create a schema using the authorization
ID of SMITH. Create a student table that has a comment on the student number
column. </p>
<pre class="xmp"> <span class="bold">CREATE SCHEMA AUTHORIZATION</span> SMITH
<span class="bold">CREATE TABLE</span> SMITH.STUDENT (STUDNBR <span class="bold">SMALLINT NOT NULL UNIQUE</span>,
LASTNAME <span class="bold">CHAR</span>(20),
FIRSTNAME <span class="bold">CHAR</span>(20),
ADDRESS <span class="bold">CHAR</span>(50))
<span class="bold">COMMENT ON</span> STUDENT (STUDNBR <span class="bold">IS</span> 'THIS IS A UNIQUE ID#')</pre><a id="idx2032" name="idx2032"></a><a id="idx2033" name="idx2033"></a>
<hr /><br />
[ <a href="#Top_Of_Page">Top of Page</a> | <a href="rbafzmstcrtpsf.htm">Previous Page</a> | <a href="rbafzmstcsequence.htm">Next Page</a> | <a href="rbafzmst02.htm#wq1">Contents</a> |
<a href="rbafzmstindex.htm#index">Index</a> ]
<a id="Bot_Of_Page" name="Bot_Of_Page"></a>
</body>
</html>