doc-exports/docs/dws/dev/dws_06_0173.html
Lu, Huayi a24ca60074 DWS DEVELOPER 811 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2023-01-19 13:37:49 +00:00

52 lines
10 KiB
HTML

<a name="EN-US_TOPIC_0000001098830912"></a><a name="EN-US_TOPIC_0000001098830912"></a>
<h1 class="topictitle1">CREATE SCHEMA</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001098830912__s628a72e4ad6147cf9cc089febf125678"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001098830912__en-us_topic_0059777945_p549110246542"><strong id="EN-US_TOPIC_0000001098830912__b842352706173217">CREATE SCHEMA</strong> creates a schema.</p>
<p id="EN-US_TOPIC_0000001098830912__a0ffd19c6ba5e4023bff33e70ba93367b">Named objects are accessed either by "qualifying" their names with the schema name as a prefix, or by setting a search path that includes the desired schema(s). When creating named objects, you can also use the schema name as a prefix.</p>
<p id="EN-US_TOPIC_0000001098830912__acfdefd1c708c4c1593590de6f8a742b7">Optionally, <strong id="EN-US_TOPIC_0000001098830912__b32932289135258">CREATE SCHEMA</strong> can include sub-commands to create objects within the new schema. The sub-commands are treated essentially the same as separate commands issued after creating the schema, If the <strong id="EN-US_TOPIC_0000001098830912__b842352706153719">AUTHORIZATION</strong> clause is used, all the created objects are owned by this user.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830912__sd8a756b505184705a8897156f5eb52c1"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001098830912__ul795312913276"><li id="EN-US_TOPIC_0000001098830912__li1695317294272">As long as the current user has the CREATE permission, the user can create a schema.</li><li id="EN-US_TOPIC_0000001098830912__li10953229182712">The owner of an object created by a system administrator in a schema with the same name as a common user is the common user, not the system administrator.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830912__s6d289579f18149c1a17ec06712dde98a"><h4 class="sectiontitle">Syntax</h4><ul id="EN-US_TOPIC_0000001098830912__ueb686891603d403480637aa0cf189f2c"><li id="EN-US_TOPIC_0000001098830912__la0976fa1070d4c8b9088a4ed573350f2">Create a schema based on a specified name.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830912__sa863f654e9d44d4f9bbc808b7ee28222"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">SCHEMA</span><span class="w"> </span><span class="k">schema_name</span><span class="w"> </span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">AUTHORIZATION</span><span class="w"> </span><span class="n">user_name</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="n">PERM</span><span class="w"> </span><span class="k">SPACE</span><span class="w"> </span><span class="s1">'space_limit'</span><span class="p">]</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">schema_element</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">];</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</li><li id="EN-US_TOPIC_0000001098830912__l191a2077497d462c88cfbcee6848037c">Create a schema based on a user name.<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001098830912__s75304cfa12934b3b83df7cae6d5c8728"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">CREATE</span><span class="w"> </span><span class="k">SCHEMA</span><span class="w"> </span><span class="k">AUTHORIZATION</span><span class="w"> </span><span class="n">user_name</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="n">PERM</span><span class="w"> </span><span class="k">SPACE</span><span class="w"> </span><span class="s1">'space_limit'</span><span class="p">]</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="n">schema_element</span><span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]</span><span class="w"> </span><span class="p">];</span><span class="w"></span>
</pre></div></td></tr></table></div>
</div>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830912__s137c7d80e527499da3008e35aa5115aa"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001098830912__ub308d7ce1ea94a509a9fa185772ce356"><li id="EN-US_TOPIC_0000001098830912__lf6df67d8504e48428af0f53cf4ced03f"><strong id="EN-US_TOPIC_0000001098830912__af0784a43101c4e78b5083c98d58a40c0">schema_name</strong><p id="EN-US_TOPIC_0000001098830912__a2115acd4630e42e78f9032aef52c2541">Indicates the name of the schema to be created.</p>
<div class="notice" id="EN-US_TOPIC_0000001098830912__n7c79f5a45287445cbd1241ff5145bad7"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="EN-US_TOPIC_0000001098830912__a471e4e5e2d4e42a6b738af1592ed3076">The name must be unique, </p>
<p id="EN-US_TOPIC_0000001098830912__a8ade7e0c6bac43d38dc35989dfdc79f2">and cannot start with <strong id="EN-US_TOPIC_0000001098830912__b59010337174627">pg_</strong>.</p>
</div></div>
<p id="EN-US_TOPIC_0000001098830912__a0bbc161a37a64d1ab6b735d0363eaa54">Value range: a string. It must comply with the naming convention rule.</p>
</li><li id="EN-US_TOPIC_0000001098830912__l4676a2dbfd484819858b12ad8e546b30"><strong id="EN-US_TOPIC_0000001098830912__a4d0fa29a8cb445c88aaf404f24740da7">AUTHORIZATION user_name</strong><p id="EN-US_TOPIC_0000001098830912__a724c2de5a7b34ea384d2b497c9ad0bd7">Indicates the name of the user who will own this schema. If <strong id="EN-US_TOPIC_0000001098830912__en-us_topic_0058966152_b16195942174627">schema_name</strong> is not specified, <strong id="EN-US_TOPIC_0000001098830912__en-us_topic_0058966152_b11545754174627">user_name</strong> will be used as the schema name. In this case, <strong id="EN-US_TOPIC_0000001098830912__en-us_topic_0058966152_b36802925174627">user_name</strong> can only be a role name.</p>
<p id="EN-US_TOPIC_0000001098830912__a62ab8950e22041369b3b4329bab70fb1">Value range: An existing user name/role.</p>
</li><li id="EN-US_TOPIC_0000001098830912__li1566194263915"><strong id="EN-US_TOPIC_0000001098830912__b86610421397">WITH PERM SPACE 'space_limit'</strong><p id="EN-US_TOPIC_0000001098830912__p36612424397">Indicates the storage upper limit of the permanent table in the specified schema. If <strong id="EN-US_TOPIC_0000001098830912__b57121655103217">space_limit</strong> is not specified, the space is not limited.</p>
<p id="EN-US_TOPIC_0000001098830912__p766114214399">Value range: A string consists of an integer and unit. The unit can be K/M/G/T/P currently. The unit of parsed value is K and cannot exceed the range that can be expressed in 64 bits, which is 1 KB to 9007199254740991 KB.</p>
</li><li id="EN-US_TOPIC_0000001098830912__lc1d779f3255e4b9cb81d8d0f7b549d7a"><strong id="EN-US_TOPIC_0000001098830912__a0976e211b7af4e9fad8c24d4ebb895a8">schema_element</strong><p id="EN-US_TOPIC_0000001098830912__acab2a4ed92e049a3b4f5f4494ba7d742">Indicates an SQL statement defining an object to be created within the schema. Currently, only <strong id="EN-US_TOPIC_0000001098830912__b20811126174627">CREATE TABLE</strong>, <strong id="EN-US_TOPIC_0000001098830912__b53082411174627">CREATE VIEW</strong>, <strong id="EN-US_TOPIC_0000001098830912__b7979658174627">CREATE INDEX</strong>, <strong id="EN-US_TOPIC_0000001098830912__b4708058174627">CREATE PARTITION</strong>, and <strong id="EN-US_TOPIC_0000001098830912__b84235270620473">GRANT</strong> are accepted as clauses within <strong id="EN-US_TOPIC_0000001098830912__b9622538174627">CREATE SCHEMA</strong>.</p>
<p id="EN-US_TOPIC_0000001098830912__a31a7e8559d684565ad276e5c3ef84714">Objects created by sub-commands are owned by the user specified by <strong id="EN-US_TOPIC_0000001098830912__b51142028174627">AUTHORIZATION</strong>.</p>
</li></ul>
<div class="note" id="EN-US_TOPIC_0000001098830912__n9a9767ebd2724611b35932b1d8cf3ef5"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001098830912__af946322ebcb441e8a11af77cc9fd97ee">If objects in the schema on the current search path are with the same name, specify the schemas different objects are in. You can run the <strong id="EN-US_TOPIC_0000001098830912__b2388300813553">SHOW SEARCH_PATH</strong> command to check the schemas on the current search path.</p>
</div></div>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830912__s5bf3a4d02e2d4bea92404b3442f9ffb8"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001098830912__p024849145311">Create a schema named <strong id="EN-US_TOPIC_0000001098830912__b752932124150">role1</strong> for the <strong id="EN-US_TOPIC_0000001098830912__b9456995264150">role1</strong> role. The owner of the <strong id="EN-US_TOPIC_0000001098830912__b7296903414150">films</strong> and <strong id="EN-US_TOPIC_0000001098830912__b12715565454150">winners</strong> tables created by the clause is <strong id="EN-US_TOPIC_0000001098830912__b6756184704150">role1</strong>.</p>
<pre class="screen" id="EN-US_TOPIC_0000001098830912__screen26935514532">CREATE SCHEMA AUTHORIZATION role1
CREATE TABLE films (title text, release date, awards text[])
CREATE VIEW winners AS
SELECT title, release FROM films WHERE awards IS NOT NULL;</pre>
</div>
<div class="section" id="EN-US_TOPIC_0000001098830912__sf5b9082b29dc4619be18df64147e273a"><h4 class="sectiontitle">Helpful Links</h4><p id="EN-US_TOPIC_0000001098830912__ab9d043f673ca47ea82b9e1b144d08686"><a href="dws_06_0136.html">ALTER SCHEMA</a>, <a href="dws_06_0204.html">DROP SCHEMA</a></p>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_06_0118.html">DDL Syntax</a></div>
</div>
</div>