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 数据源.表名 update 列1 = 列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);