clickhouse 建表语句
时间: 2023-09-13 14:09:36 浏览: 96
ClickHouse的建表语句可以通过两种方式指定主键。一种是通过内部定义的方式,在CREATE TABLE语句中使用PRIMARY KEY关键字来定义主键,如下所示:
```
CREATE TABLE db.table_name (
name1 type1,
name2 type2,
...
PRIMARY KEY(expr1[, expr2,...])
) ENGINE = engine;
```
另一种是通过外部定义的方式,在CREATE TABLE语句中不使用PRIMARY KEY关键字,而是在表定义完成后再单独指定主键,如下所示:
```
CREATE TABLE db.table_name (
name1 type1,
name2 type2,
...
) ENGINE = engine PRIMARY KEY(expr1[, expr2,...]);
```
此外,ClickHouse还支持临时字段列,这些列不存储在表中,不能被SELECT查询,但可以在CREATE语句的默认值中引用。还有别名表达式可以在建表语句中使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [ClickHouse(06)ClickHouse建表语句DDL详细解析](https://blog.csdn.net/u014470784/article/details/126894440)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文