Clickhouse常用sql

SQL语句

1.增加

jdbcTemplate.execute(sql)

//生成表
CREATE TABLE 表名
(
    `列名1` String,
    `列名2` String,
    `列名3` DateTime
)
ENGINE = ReplacingMergeTree   //引擎类型
PARTITION BY 列名3            //分区
PRIMARY KEY (列名1)           //主键
ORDER BY (列名1)              //排序
SETTINGS index_granularity = 8192  //粒度
//插入语句
insert into 表名 (列名1,列名2...) values ('xxx','xxx'...)
//添加列
alter table 数据源.表名 add column 列名 类型 (长度,精度) comment 描述
//复制一列数据到另一列
alter table 数据源.表名 update1 =2 where 1=1

2.删除

jdbcTemplate.update(sql)

//删除数据库
drop 数据库名
//删除表
drop table 表名
drop table if exists 数据源.表名
//删除表中所有数据(无法回滚风险较高,truncate table操作会等待所有的副本处理结束,即使某些副本出现故障了,也还会继续等待,没有设置超时时间)
truncate table 表名
//删除列
alter table 表名 drop column 列名1
//删除数据
alter table 表名 delete where ...
//删除视图
drop view if exists 数据源.表名

3.更新

insert into 表名 (列名1,列名2...) values ('xxx','xxx'...)

4.查询

jdbcTemplate.queryForList(sql,表名,数据源)

//查询列名1,列名2是否存在于表中
SELECT name from system.columns where table='表名' and database='数据库名' and name in (列名1,列名2)
//查询表主键
SELECT name FROM system.columns WHERE table = '表名' AND database = '库名' AND is_in_primary_key = 1
//查询表所有字段
SELECT name from system.columns where table = ? and database = ?

5.其他

//手动合并分区数据
optimize table 表名 final
//系统正在执行的命令
select * from system.processes
//复制表中信息
insert into 表名 (字段名1,字段名2....) select 字段名1,xxx,... from 表名 where ...

JdbcTemplate方法使用

1.创建库或者表、删除列、复制一列数据到另一列、删除数据

jdbcTemplate.execute(sql);

2.删除表、删除视图

jdbcTemplate.update(sql);

3.查询字段是否存在、查询表主键

jdbcTemplate.queryForList(sql, 数据源, 表名);

4.批量插入数据、更新数据、参数删除数据

//批量
jdbcTemplate.batchUpdate(sqls);
//单个、参数删除数据
jdbcTemplate.update(sql);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值