forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Yang, Tong <yangtong2@huawei.com> Co-committed-by: Yang, Tong <yangtong2@huawei.com>
28 lines
2.2 KiB
HTML
28 lines
2.2 KiB
HTML
<a name="mrs_01_24200"></a><a name="mrs_01_24200"></a>
|
|
|
|
<h1 class="topictitle1">CREATE DATABASE: Creating a Database</h1>
|
|
<div id="body0000001138846338"><p id="mrs_01_24200__p1919324122119">This section describes the basic syntax and usage of the SQL statement for creating a ClickHouse database.</p>
|
|
<div class="section" id="mrs_01_24200__section19309143941918"><h4 class="sectiontitle">Basic Syntax</h4><p id="mrs_01_24200__p2961134612212"><strong id="mrs_01_24200__b1346777388105842">CREATE DATABASE [IF NOT EXISTS] </strong> <em id="mrs_01_24200__i1649389035105842">Database_name</em> <strong id="mrs_01_24200__b1094990268105842">[ON CLUSTER </strong><em id="mrs_01_24200__i987015198105842">ClickHouse cluster name</em><strong id="mrs_01_24200__b1534734649105842">]</strong></p>
|
|
<p id="mrs_01_24200__p7693516201517"></p>
|
|
<div class="note" id="mrs_01_24200__note777793976"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="mrs_01_24200__p19741613771">The syntax <strong id="mrs_01_24200__b1286049629105842">ON CLUSTER</strong> <em id="mrs_01_24200__i1585824901105842">ClickHouse cluster name</em> enables the Data Definition Language (DDL) statement to be executed on all instances in the cluster at a time. You can run the following statement to obtain the cluster name from the <strong id="mrs_01_24200__b19361101012716">cluster</strong> field:</p>
|
|
<p id="mrs_01_24200__p123618101175"><strong id="mrs_01_24200__b143612102713">select cluster,shard_num,replica_num,host_name from system.clusters;</strong></p>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="mrs_01_24200__section182821849171918"><h4 class="sectiontitle">Example</h4><pre class="screen" id="mrs_01_24200__screen099037123115">-- Create a database named <strong id="mrs_01_24200__b104987233105842">test</strong>.
|
|
CREATE DATABASE test ON CLUSTER default_cluster;
|
|
-- After the creation is successful, run the query command for verification.
|
|
show databases;
|
|
┌─name───┐
|
|
│ default │
|
|
│ system │
|
|
│ test │
|
|
└──────┘</pre>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_24199.html">Common ClickHouse SQL Syntax</a></div>
|
|
</div>
|
|
</div>
|
|
|