Help Center/ MapReduce Service/ Developer Guide (LTS)/ ClickHouse Development Guide (Security Mode)/ Developing a ClickHouse Application/ Creating a ClickHouse Table
Updated on 2026-04-09 GMT+08:00
Creating a ClickHouse Table
This section describes how to create a ClickHouse table.
Run the on cluster statement to create the ReplicatedMerge and Distributed tables whose names are the same as the values of tableName in Table 1.
The following sample code is for reference only:
private void createTable(String databaseName, String tableName, String clusterName) throws Exception {
String createSql = "create table " + databaseName + "." + tableName + " on cluster " + clusterName + " (name String, age UInt8, date Date)engine=ReplicatedMergeTree('/clickhouse/tables/{shard}/" + databaseName + "." + tableName + "'," + "'{replica}') partition by toYYYYMM(date) order by age";
String createDisSql = "create table " + databaseName + "." + tableName + "_all" + " on cluster " + clusterName + " as " + databaseName + "." + tableName + " ENGINE = Distributed(default_cluster," + databaseName + "," + tableName + ", rand());"; ArrayList<String> sqlList = new ArrayList<String>();
sqlList.add(createSql);
sqlList.add(createDisSql);
util.exeSql(sqlList);
} Parent topic: Developing a ClickHouse Application
What is your overall rating for this page?
0
1
2
3
4
5
6
7
8
9
10
Very dissatisfiedVery satisfied
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot