赞
踩
1.新增
insert into tableName field1,field2,... values(value1,value2,...);
2.删除
alter table tableName delete where 1=1;
删除一定要带where条件
3.修改
alter table tableName update field1='value' where field1='orgValue'
4.查询
select field1,field2 from tableName where field1=2;
5.新增字段
alter table tableName add column `columnName` 字段类型;
6.删除字段
alter table tableName drop column `columnName` ;
7.表重命名
rename table A to B
8.修改字段类型(慎用Nullable)
alter table tableName MODIFY COLUMN fieldName 字段类型;
9.创建TTL
已存在表添加TTL
alter table tableName modify TTL create_date + INTERVAL +1 DAY
创建表时增加TTL
CREATE TABLE example_table (
`event_date` Date,
`uid` Int32,
`name` String
)
ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/example_table', '{replica}')
PARTITION BY event_date
ORDER BY uid
TTL event_date + toIntervalMonth(1)
SETTINGS index_granularity = 128;
# 修改表的 TTL,event_date超过三个月的数据自动删除
ALTER TABLE example_table MODIFY TTL event_date + toIntervalMonth(3);
10.删除分区
alter table 表名 drop partition partitionName;
分区查询:
select * from system.parts p where table = '表名'
11.添加注释
ALTER TABLE tableName COMMENT COLUMN columnName '注释信息';
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。