forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: Lu, Huayi <luhuayi@huawei.com> Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
60 lines
13 KiB
HTML
60 lines
13 KiB
HTML
<a name="EN-US_TOPIC_0000001510161333"></a><a name="EN-US_TOPIC_0000001510161333"></a>
|
|
|
|
<h1 class="topictitle1">CREATE SCHEMA</h1>
|
|
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001510161333__s628a72e4ad6147cf9cc089febf125678"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001510161333__en-us_topic_0059777945_p549110246542">Creates a schema.</p>
|
|
<p id="EN-US_TOPIC_0000001510161333__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_0000001510161333__acfdefd1c708c4c1593590de6f8a742b7">Optionally, <strong id="EN-US_TOPIC_0000001510161333__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_0000001510161333__b842352706153719">AUTHORIZATION</strong> clause is used, all the created objects are owned by this user.</p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001510161333__sd8a756b505184705a8897156f5eb52c1"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001510161333__ul795312913276"><li id="EN-US_TOPIC_0000001510161333__li1695317294272">As long as the current user has the CREATE permission, the user can create a schema.</li><li id="EN-US_TOPIC_0000001510161333__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_0000001510161333__s6d289579f18149c1a17ec06712dde98a"><h4 class="sectiontitle">Syntax</h4><ul id="EN-US_TOPIC_0000001510161333__ueb686891603d403480637aa0cf189f2c"><li id="EN-US_TOPIC_0000001510161333__la0976fa1070d4c8b9088a4ed573350f2">Create a schema based on a specified name:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001510161333__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>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</li><li id="EN-US_TOPIC_0000001510161333__l191a2077497d462c88cfbcee6848037c">Create a schema based on a username:<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001510161333__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>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
</li></ul>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001510161333__s137c7d80e527499da3008e35aa5115aa"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001510161333__ub308d7ce1ea94a509a9fa185772ce356"><li id="EN-US_TOPIC_0000001510161333__lf6df67d8504e48428af0f53cf4ced03f"><strong id="EN-US_TOPIC_0000001510161333__af0784a43101c4e78b5083c98d58a40c0">schema_name</strong><p id="EN-US_TOPIC_0000001510161333__a2115acd4630e42e78f9032aef52c2541">Indicates the name of the schema to be created.</p>
|
|
<div class="notice" id="EN-US_TOPIC_0000001510161333__n7c79f5a45287445cbd1241ff5145bad7"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="EN-US_TOPIC_0000001510161333__a8ade7e0c6bac43d38dc35989dfdc79f2"></p>
|
|
<ul id="EN-US_TOPIC_0000001510161333__ul13364185615206"><li id="EN-US_TOPIC_0000001510161333__li7364155610208">The name must be unique, </li><li id="EN-US_TOPIC_0000001510161333__li536455622010">and cannot start with <strong id="EN-US_TOPIC_0000001510161333__b59010337174627">pg_</strong>.</li></ul>
|
|
</div></div>
|
|
<p id="EN-US_TOPIC_0000001510161333__a0bbc161a37a64d1ab6b735d0363eaa54">Value range: a string. It must comply with the naming convention rule.</p>
|
|
</li><li id="EN-US_TOPIC_0000001510161333__l4676a2dbfd484819858b12ad8e546b30"><strong id="EN-US_TOPIC_0000001510161333__a4d0fa29a8cb445c88aaf404f24740da7">AUTHORIZATION user_name</strong><p id="EN-US_TOPIC_0000001510161333__a724c2de5a7b34ea384d2b497c9ad0bd7">Indicates the name of the user who will own this schema. If <strong id="EN-US_TOPIC_0000001510161333__en-us_topic_0058966152_b16195942174627">schema_name</strong> is not specified, <strong id="EN-US_TOPIC_0000001510161333__en-us_topic_0058966152_b11545754174627">user_name</strong> will be used as the schema name. In this case, <strong id="EN-US_TOPIC_0000001510161333__en-us_topic_0058966152_b36802925174627">user_name</strong> can only be a role name.</p>
|
|
<p id="EN-US_TOPIC_0000001510161333__a62ab8950e22041369b3b4329bab70fb1">Value range: An existing user name/role.</p>
|
|
</li><li id="EN-US_TOPIC_0000001510161333__li1566194263915"><strong id="EN-US_TOPIC_0000001510161333__b86610421397">WITH PERM SPACE 'space_limit'</strong><p id="EN-US_TOPIC_0000001510161333__p36612424397">Indicates the storage upper limit of the permanent table in the specified schema. If <strong id="EN-US_TOPIC_0000001510161333__b57121655103217">space_limit</strong> is not specified, the space is not limited.</p>
|
|
<p id="EN-US_TOPIC_0000001510161333__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_0000001510161333__lc1d779f3255e4b9cb81d8d0f7b549d7a"><strong id="EN-US_TOPIC_0000001510161333__a0976e211b7af4e9fad8c24d4ebb895a8">schema_element</strong><p id="EN-US_TOPIC_0000001510161333__acab2a4ed92e049a3b4f5f4494ba7d742">Indicates an SQL statement defining an object to be created within the schema. Currently, only <strong id="EN-US_TOPIC_0000001510161333__b20811126174627">CREATE TABLE</strong>, <strong id="EN-US_TOPIC_0000001510161333__b53082411174627">CREATE VIEW</strong>, <strong id="EN-US_TOPIC_0000001510161333__b7979658174627">CREATE INDEX</strong>, <strong id="EN-US_TOPIC_0000001510161333__b4708058174627">CREATE PARTITION</strong>, and <strong id="EN-US_TOPIC_0000001510161333__b84235270620473">GRANT</strong> are accepted as clauses within <strong id="EN-US_TOPIC_0000001510161333__b9622538174627">CREATE SCHEMA</strong>.</p>
|
|
<p id="EN-US_TOPIC_0000001510161333__a31a7e8559d684565ad276e5c3ef84714">Objects created by sub-commands are owned by the user specified by <strong id="EN-US_TOPIC_0000001510161333__b51142028174627">AUTHORIZATION</strong>.</p>
|
|
</li></ul>
|
|
<div class="note" id="EN-US_TOPIC_0000001510161333__n9a9767ebd2724611b35932b1d8cf3ef5"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001510161333__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_0000001510161333__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_0000001510161333__s5bf3a4d02e2d4bea92404b3442f9ffb8"><h4 class="sectiontitle">Examples</h4><p id="EN-US_TOPIC_0000001510161333__p16145115031914">-- Create the <strong id="EN-US_TOPIC_0000001510161333__b152637805633619">role1</strong> role.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001510161333__screen126111355181914"><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">ROLE</span><span class="w"> </span><span class="n">role1</span><span class="w"> </span><span class="n">IDENTIFIED</span><span class="w"> </span><span class="k">BY</span><span class="w"> </span><span class="s1">'{password}'</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001510161333__p201459508198">Create a schema named <strong id="EN-US_TOPIC_0000001510161333__b102965564533619">role1</strong> for the <strong id="EN-US_TOPIC_0000001510161333__b150851098733619">role1</strong> role. The owner of the <strong id="EN-US_TOPIC_0000001510161333__b59598001233619">films</strong> and <strong id="EN-US_TOPIC_0000001510161333__b62549231233619">winners</strong> tables created by the clause is <strong id="EN-US_TOPIC_0000001510161333__b164750029633619">role1</strong>.</p>
|
|
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001510161333__screen1845618282013"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
|
|
<span class="normal">2</span>
|
|
<span class="normal">3</span>
|
|
<span class="normal">4</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">role1</span>
|
|
<span class="w"> </span><span class="k">CREATE</span><span class="w"> </span><span class="k">TABLE</span><span class="w"> </span><span class="n">films</span><span class="w"> </span><span class="p">(</span><span class="n">title</span><span class="w"> </span><span class="nb">text</span><span class="p">,</span><span class="w"> </span><span class="n">release</span><span class="w"> </span><span class="nb">date</span><span class="p">,</span><span class="w"> </span><span class="n">awards</span><span class="w"> </span><span class="nb">text</span><span class="p">[])</span><span class="w"> </span>
|
|
<span class="w"> </span><span class="k">CREATE</span><span class="w"> </span><span class="k">VIEW</span><span class="w"> </span><span class="n">winners</span><span class="w"> </span><span class="k">AS</span><span class="w"> </span>
|
|
<span class="w"> </span><span class="k">SELECT</span><span class="w"> </span><span class="n">title</span><span class="p">,</span><span class="w"> </span><span class="n">release</span><span class="w"> </span><span class="k">FROM</span><span class="w"> </span><span class="n">films</span><span class="w"> </span><span class="k">WHERE</span><span class="w"> </span><span class="n">awards</span><span class="w"> </span><span class="k">IS</span><span class="w"> </span><span class="k">NOT</span><span class="w"> </span><span class="k">NULL</span><span class="p">;</span>
|
|
</pre></div></td></tr></table></div>
|
|
</div>
|
|
<p id="EN-US_TOPIC_0000001510161333__p171451350101910"></p>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001510161333__sf5b9082b29dc4619be18df64147e273a"><h4 class="sectiontitle">Helpful Links</h4><p id="EN-US_TOPIC_0000001510161333__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>
|
|
|