Updated on 2024-10-23 GMT+08:00

Deleting a ClickHouse Table

This section describes the sample code for deleting a ClickHouse table.

The following code snippet is provided in the dropTable method of the Demo class in the com.huawei.clickhouse.examples package.

The code snippet deletes the backup table and distributed table created in Creating a ClickHouse Table.

private void dropTable(String databaseName, String tableName, String clusterName) throws Exception {
    String dropLocalTableSql = "drop table if exists " + databaseName + "." + tableName + " on cluster " + clusterName;
    String dropDisTableSql = "drop table if exists " + databaseName + "." + tableName + "_all" + " on cluster " + clusterName;
    ArrayList<String> sqlList = new ArrayList<String>();
    sqlList.add(dropLocalTableSql);
    sqlList.add(dropDisTableSql);
    util.exeSql(sqlList);
}