CilckHouse创建表

一、引擎
一开始没注意有引擎选择,要用什么引擎去官方文档看看自己建的表适合什么引擎,大部分用MergeTree
二、用sql语句生成表
1、MergeTree引擎

原文地址:https://blog.csdn.net/qq_21383435/article/details/122812921?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522169511347516800186516829%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=169511347516800186516829&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-3-122812921-null-null.142v94control&utm_term=clickhouse%E5%BB%BA%E8%A1%A8&spm=1018.2226.3001.4187

CREATE TABLE default.RFDeviceLog
(
   ID UUID ,    
	LoginMan String,   
	LoginTime DateTime,   
	DeviceNo String,   
	LoginType String
) 
ENGINE = MergeTree()
ORDER BY LoginTime

---ORDER BY必填,否则报错----

完整语法:

CREATE TABLE [IF NOT EXISTS] [db.]table_name [ON CLUSTER cluster]
(
name1 [type1] [DEFAULT|MATERIALIZED|ALIAS expr1] [TTL expr1],
name2 [type2] [DEFAULT|MATERIALIZED|ALIAS expr2] [TTL expr2],

INDEX index_name1 expr1 TYPE type1(…) GRANULARITY value1,
INDEX index_name2 expr2 TYPE type2(…) GRANULARITY value2
) ENGINE = MergeTree()
ORDER BY expr --排序键
[PARTITION BY expr] --分区键
[PRIMARY KEY expr] – 主键
[SAMPLE BY expr] --抽样表达式
[TTL expr [DELETE|TO DISK ‘xxx’|TO VOLUME ‘xxx’], …]
[SETTINGS name=value, …]
//ORDER BY必填,否则报错
//[]表示可填可不填,填了则求掉[]

你可能感兴趣的:(ClickHOuse,笔记,clickhouse)