This topic describes the statements used to create a table for a master-replica ApsaraDB for ClickHouse cluster and a standalone ApsaraDB for ClickHouse cluster.

Standalone cluster

1. Create a local table.

CREATE TABLE default.sls_test_single_local on cluster default(
`v1` Int8, 
`v2` Int16, 
`v3` Int32, 
`v4` Int64, 
`v5` UInt8, 
`v6` UInt16, 
`v7` UInt32, 
`v8` UInt64, 
`v9` Decimal(10, 2), 
`v10` Float32, 
`v11` Float64, 
`v12` String, 
`v13` FixedString(10), 
`v14` UUID, `v15` Date, 
`v16` DateTime, 
`v17` Enum8('hello' = 1, 'world' = 2), 
`v18` Enum16('hello' = 1, 'world' = 2), 
`v19` IPv4, 
`v20` IPv6) 
ENGINE = MergeTree() PARTITION BY toYYYYMMDD(v16) ORDER BY v4 SETTINGS index_granularity = 8192;

2. Create a distributed table to facilitate data writing and queries.

CREATE TABLE sls_test_single_d ON CLUSTER default as sls_test_single_local ENGINE = Distributed(default, default, sls_test_single_local, rand());

Master-replica cluster

The table engine used to create a table on a master-replica cluster is different from the table engine used to create a table in a standalone cluster. To create a table on a master-replica cluster, select the ReplicatedMergeTree table engine.

  1. Create a local table.
    CREATE TABLE default.sls_test_local ON CLUSTER default (
    `v1` Int8, 
    `v2` Int16, 
    `v3` Int32, 
    `v4` Int64, 
    `v5` UInt8, 
    `v6` UInt16, 
    `v7` UInt32, 
    `v8` UInt64, 
    `v9` Decimal(10, 2), 
    `v10` Float32, 
    `v11` Float64, 
    `v12` String, 
    `v13` FixedString(10), 
    `v14` UUID, `v15` Date, 
    `v16` DateTime, 
    `v17` Enum8('hello' = 1, 'world' = 2), 
    `v18` Enum16('hello' = 1, 'world' = 2), 
    `v19` IPv4, 
    `v20` IPv6) 
    ENGINE = ReplicatedMergeTree('/clickhouse/tables/{database}/{table}/{shard}', '{replica}') 
    PARTITION BY toYYYYMMDD(v16) ORDER BY v4 SETTINGS index_granularity = 8192
  2. Create a distributed table to facilitate data writing and queries.
    CREATE TABLE sls_test_d ON CLUSTER default as sls_test_local ENGINE = Distributed(default, default, sls_test_local, rand());