Files
doc-exports/docs/dws/dev/dws_06_0285.html
luhuayi 177cd61a57 DWS DEVG 910.211 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: luhuayi <luhuayi@huawei.com>
Co-committed-by: luhuayi <luhuayi@huawei.com>
2025-05-05 07:44:03 +00:00

84 lines
11 KiB
HTML

<a name="EN-US_TOPIC_0000001811634585"></a><a name="EN-US_TOPIC_0000001811634585"></a>
<h1 class="topictitle1">CREATE PUBLICATION</h1>
<div id="body0000001441713546"><div class="section" id="EN-US_TOPIC_0000001811634585__sf337ecb5bde84580afed94be7bbf5fb9"><h4 class="sectiontitle">Function</h4><p id="EN-US_TOPIC_0000001811634585__p11941336171015"><strong id="EN-US_TOPIC_0000001811634585__b817210519229">CREATE PUBLICATION</strong> adds a new publication to the current database. The publication name must be different from the name of any existing publication in the current database. A publication is essentially the replication of data changes in a set of tables achieved by logical replication.</p>
</div>
<div class="section" id="EN-US_TOPIC_0000001811634585__section93413620440"><h4 class="sectiontitle">Precautions</h4><ul id="EN-US_TOPIC_0000001811634585__ul10234635104412"><li id="EN-US_TOPIC_0000001811634585__li2741103217711">This statement is supported by version 8.2.0.100 or later clusters.</li><li id="EN-US_TOPIC_0000001811634585__li158597016496">If neither <strong id="EN-US_TOPIC_0000001811634585__b181308989632229">FOR TABLE</strong> nor <strong id="EN-US_TOPIC_0000001811634585__b66800140032229">FOR ALL TABLES</strong> is specified, a publication starts with a set of empty tables. Tables can be added later.</li><li id="EN-US_TOPIC_0000001811634585__li0343151318106">Creating a publication does not start replication. It defines only one group and filtering logic for future subscribers. To create a publication, the caller must have CREATE permission on the current database.</li><li id="EN-US_TOPIC_0000001811634585__li2393131774711">To add a table to a publication, the caller must have ownership of the table. To use FOR ALL TABLES and FOR ALL TABLES IN SCHEMA clauses, the caller must have system administrator permissions.</li><li id="EN-US_TOPIC_0000001811634585__li127513452616">Do not add a table to the same publication by using FOR TABLE and FOR ALL TABLES IN SCHEMA.</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001811634585__s432427bf362e4684b4559ac16cfcda57"><h4 class="sectiontitle">Syntax</h4><div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001811634585__s18d476418c7748ada6302a1c75028d5d"><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="n">PUBLICATION</span><span class="w"> </span><span class="n">name</span>
<span class="w"> </span><span class="p">[</span><span class="w"> </span><span class="k">FOR</span><span class="w"> </span><span class="k">ALL</span><span class="w"> </span><span class="n">TABLES</span>
<span class="w"> </span><span class="o">|</span><span class="w"> </span><span class="k">FOR</span><span class="w"> </span><span class="n">publication_object</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><span class="p">[</span><span class="w"> </span><span class="k">WITH</span><span class="w"> </span><span class="p">(</span><span class="w"> </span><span class="n">publication_parameter</span><span class="w"> </span><span class="p">[</span><span class="o">=</span><span class="n">value</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><span class="p">)</span><span class="w"> </span><span class="p">];</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001811634585__p11662172719480">The syntax of using <strong id="EN-US_TOPIC_0000001811634585__b921772062918">publication_object</strong> is as follows:</p>
<pre class="screen" id="EN-US_TOPIC_0000001811634585__screen370754012485">TABLE table_name [, ...]
| ALL TABLES IN SCHEMA schema_name [, ... ]</pre>
</div>
<div class="section" id="EN-US_TOPIC_0000001811634585__section1549681213574"><h4 class="sectiontitle">Parameter Description</h4><ul id="EN-US_TOPIC_0000001811634585__ul849711245713"><li id="EN-US_TOPIC_0000001811634585__li11885054185912"><strong id="EN-US_TOPIC_0000001811634585__b614481895914">name</strong><p id="EN-US_TOPIC_0000001811634585__p836651861419">Specifies the name of a new publication.</p>
<p id="EN-US_TOPIC_0000001811634585__p967943011145">Value range: A string. It must comply with the naming convention.</p>
</li><li id="EN-US_TOPIC_0000001811634585__li17392131613264"><strong id="EN-US_TOPIC_0000001811634585__b666192015277">FOR ALL TABLES</strong><p id="EN-US_TOPIC_0000001811634585__p2039210167263">Marks a publication as replications of all fines-grained DR primary table changes in the database, including tables to be created.</p>
</li><li id="EN-US_TOPIC_0000001811634585__li18542153412134"><strong id="EN-US_TOPIC_0000001811634585__b3903123222612">FOR TABLE</strong><p id="EN-US_TOPIC_0000001811634585__p571312461613">Specifies the list of tables to be added to a publication. Only the fine-grained DR primary table can be a part of the publication.</p>
</li><li id="EN-US_TOPIC_0000001811634585__li936911122616"><strong id="EN-US_TOPIC_0000001811634585__b17138132718">table_name</strong><p id="EN-US_TOPIC_0000001811634585__p5369813267">Name of the table to be added to the publication, which can include the schema name.</p>
<p id="EN-US_TOPIC_0000001811634585__p143691619268">Value range: A string. It must comply with the naming convention.</p>
</li><li id="EN-US_TOPIC_0000001811634585__li68407154538"><strong id="EN-US_TOPIC_0000001811634585__b17840201513531">FOR ALL TABLES IN SCHEMA</strong><p id="EN-US_TOPIC_0000001811634585__p6840515195310">Marks a publication as replications of all fines-grained DR primary table changes a specified schema list, including tables to be created.</p>
</li><li id="EN-US_TOPIC_0000001811634585__li178401415125318"><strong id="EN-US_TOPIC_0000001811634585__b384011535311">schema_name</strong><p id="EN-US_TOPIC_0000001811634585__p13840815105319">The name of the schema to be added to the publication.</p>
<p id="EN-US_TOPIC_0000001811634585__p148401115145310">Value range: A string. It must comply with the naming convention.</p>
</li><li id="EN-US_TOPIC_0000001811634585__li11304141792615"><a name="EN-US_TOPIC_0000001811634585__li11304141792615"></a><a name="li11304141792615"></a><strong id="EN-US_TOPIC_0000001811634585__b2304317112615">WITH ( publication_parameter [=value] [, ... ] )</strong><p id="EN-US_TOPIC_0000001811634585__p14304141722613">Specifies optional parameters for a publication. The following parameters are available:</p>
<ul id="EN-US_TOPIC_0000001811634585__ul20181128153120"><li id="EN-US_TOPIC_0000001811634585__li1518114893114"><strong id="EN-US_TOPIC_0000001811634585__b01811486313">publish</strong><p id="EN-US_TOPIC_0000001811634585__p41811885318">Specifies the DML operations that will be published to the subscriber.</p>
<p id="EN-US_TOPIC_0000001811634585__p1918114812316">Value range: A string. Separate the operations by commas (,). The available operations are insert, update, delete, and truncate.</p>
<p id="EN-US_TOPIC_0000001811634585__p44819651910">By default, all actions are released. Therefore, the default value of this option is <strong id="EN-US_TOPIC_0000001811634585__b7960155431610">insert</strong>, <strong id="EN-US_TOPIC_0000001811634585__b096115491612">update</strong>, <strong id="EN-US_TOPIC_0000001811634585__b596155416165">delete</strong>, and <strong id="EN-US_TOPIC_0000001811634585__b4961115431610">truncate</strong>.</p>
</li></ul>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001811634585__section1853433744413"><h4 class="sectiontitle">Examples</h4><ul id="EN-US_TOPIC_0000001811634585__ul7431701311"><li id="EN-US_TOPIC_0000001811634585__li443170212">Create a publication for all changes of two tables and two schemas.<p id="EN-US_TOPIC_0000001811634585__p514025310213"><a name="EN-US_TOPIC_0000001811634585__li443170212"></a><a name="li443170212"></a>Create sample table <strong id="EN-US_TOPIC_0000001811634585__b2977124194910">tpcds.ship_mode_t1</strong>.</p>
<pre class="screen" id="EN-US_TOPIC_0000001811634585__screen52415585211">CREATE TABLE tpcds.ship_mode_t1
(
SM_SHIP_MODE_SK INTEGER NOT NULL,
SM_SHIP_MODE_ID CHAR(16) NOT NULL,
SM_TYPE CHAR(30) ,
SM_CODE CHAR(10) ,
SM_CARRIER CHAR(20) ,
SM_CONTRACT CHAR(20)
) WITH (ORIENTATION = COLUMN,enable_disaster_cstore='on')
DISTRIBUTE BY HASH(SM_SHIP_MODE_SK);</pre>
<p id="EN-US_TOPIC_0000001811634585__p495001941">Create sample table <strong id="EN-US_TOPIC_0000001811634585__b513637194913">tpcds.customer_address_p1</strong>.</p>
<pre class="screen" id="EN-US_TOPIC_0000001811634585__screen139061851443">CREATE TABLE tpcds.customer_address_p1
(
CA_ADDRESS_SK INTEGER NOT NULL,
CA_ADDRESS_ID CHAR(16) NOT NULL,
CA_STREET_NUMBER CHAR(10) ,
CA_STREET_NAME VARCHAR(60) ,
CA_STREET_TYPE CHAR(15) ,
CA_SUITE_NUMBER CHAR(10) ,
CA_CITY VARCHAR(60) ,
CA_COUNTY VARCHAR(30) ,
CA_STATE CHAR(2) ,
CA_ZIP CHAR(10) ,
CA_COUNTRY VARCHAR(20) ,
CA_GMT_OFFSET DECIMAL(5,2) ,
CA_LOCATION_TYPE CHAR(20)
) WITH (ORIENTATION = COLUMN,enable_disaster_cstore='on')
DISTRIBUTE BY HASH(CA_ADDRESS_SK);</pre>
<p id="EN-US_TOPIC_0000001811634585__p57171244579">Create sample schema <strong id="EN-US_TOPIC_0000001811634585__b464975254915">myschema1</strong>.</p>
<pre class="screen" id="EN-US_TOPIC_0000001811634585__screen655614121911">CREATE SCHEMA myschema1;</pre>
<p id="EN-US_TOPIC_0000001811634585__p853055316918">Create sample schema <strong id="EN-US_TOPIC_0000001811634585__b263610594496">myschema2</strong>.</p>
<pre class="screen" id="EN-US_TOPIC_0000001811634585__screen1767245818915">CREATE SCHEMA myschema2;</pre>
<p id="EN-US_TOPIC_0000001811634585__p185959010519">Create a publication for all changes of two tables and two schemas.</p>
<pre class="screen" id="EN-US_TOPIC_0000001811634585__screen536052513">CREATE PUBLICATION mypublication FOR TABLE users, departments, ALL TABLES IN SCHEMA myschema1, myschema2;</pre>
</li><li id="EN-US_TOPIC_0000001811634585__li53681442126">Create a publication for all changes in all tables.<pre class="screen" id="EN-US_TOPIC_0000001811634585__screen119110352513">CREATE PUBLICATION alltables FOR ALL TABLES;</pre>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001811634585__s7408f0450b9b4dc7948c069376053290"><h4 class="sectiontitle">Helpful Links</h4><p id="EN-US_TOPIC_0000001811634585__en-us_topic_0059778825_p749627459"><a href="dws_06_0284.html">ALTER PUBLICATION</a> <a href="dws_06_0286.html">DROP PUBLICATION</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>