1,创建数据库
CREATE DATABASE IF NOT EXISTS test_database;
集群语句(集群名称必须和搭建环境中配置环境名称一致)
// cluster_name是集群名称
CREATE DATABASE IF NOT EXISTS test_database on cluster cluster_name;
2,删除数据库
drop database test_database;
3.创建表
DROP table if exists product_id;
CREATE TABLE product_id
(
factory_goods_id UInt32 COMMENT '工厂商品ID',
goods_name String COMMENT '商品名称',
shop_id UInt32 COMMENT '店铺ID',
shop_name String COMMENT '店铺名称',
create_time DateTime COMMENT '创建时间',
update_time DateTime COMMENT '更新时间'
) ENGINE = MergeTree()
PRIMARY KEY factory_goods_id
ORDER BY factory_goods_id
DROP table if exists product_detail;
CREATE TABLE product_detail
(
factory_goods_id UInt32 COMMENT '工厂商品ID',
goods_name String COMMENT '商品名称',
goods_class_id UInt32 COMMENT '商品分类ID',
class_name String COMMENT '分类名称',
img_list Array(String) COMMENT '图片列表',
color Array(String) COMMENT '所有颜色',
introduce String COMMENT '商品介绍',
preview_img String COMMENT '预览图片',
factory_name String COMMENT '工厂名称',
sku_info String COMMENT 'sku信息',
create_time DateTime COMMENT '创建时间',
update_time DateTime COMMENT '更新时间'
) ENGINE = MergeTree()
ORDER BY factory_goods_id
PRIMARY KEY factory_goods_id
集群建表方式(集群名称必须和搭建环境中配置环境名称一致)
DROP table if exists product_id on cluster cluster_name;
CREATE TABLE product_id on cluster cluster_name
(
factory_goods_id UInt32 COMMENT '工厂商品ID',
goods_name String COMMENT '商品名称',
shop_id UInt32 COMMENT '店铺ID',
shop_name String COMMENT '店铺名称',
create_time DateTime COMMENT '创建时间',
update_time DateTime COMMENT '更新时间'
) ENGINE = MergeTree()
PRIMARY KEY factory_goods_id
ORDER BY factory_goods_id
4,添加字段
注意引擎,测试使用MergeTree
alter table product_detail add column `remark` String DEFAULT '' COMMENT '备注';
5,修改字段
alter table product_detail modify column `remark` Nullable(String) DEFAULT NULL COMMENT '备注';
6,删除字段
alter table product_detail drop column `remark`;
7,插入数据
格式
INSERT INTO [db.]table [(c1, c2, c3)] VALUES (v11, v12, v13), (v21, v22, v23), ...
示例
INSERT INTO insert_select_testtable (*) VALUES (1, 'a', 1) ;
8,删除数据
1,按分区删除
ALTER TABLE db_name.table_name DROP PARTITION '分区(例如:时间20210514)'
2,按条件删除
ALTER TABLE db_name.table_name DELETE WHERE id = 1 and name='小米'
9.更新数据
ALTER TABLE <table_name> UPDATE col1 = expr1, ... WHERE <filter>
-- 示例:
alter table table_name update name = '华为',phone = '123456' where id = 1
10,更新限制
1,索引列不能进行更新
2,分布式表不能进行更新
3,该命令是异步执行的,可以通过查看表 system.mutations 来查看命令的是否执行完毕
来源:https://blog.csdn.net/qq_41070393/article/details/116783138
标签:COMMENT,goods,name,创建,改查,table,id,clickhouse,String From: https://www.cnblogs.com/hefeng2014/p/17125798.html