数据表的基本操作

Clickhouse所提供的DDL与DML查询,在部分细节上也与其他数据库有所不同,例如update和delete是借助alter变种实现的。如下是几种常用的表操作:

  • 改变表名字 
rename table base_user to base_user_1;
  • 按条件删除数据

可以写复杂where条件

alter table base_user_1 delete where name='Name1';
  •  删除字段

对应列名及数据都会被删除

alter table base_user_1 drop column if exists tag;
  • 按条件更新数据 (不加where语句运行不了)
alter table test.qobm_1 update __label_valids = bitmapAndnot(__label_valids,
    bitmapBuild(dictGet('test.dict_label_valid_arrays', 'label_valid_arrays', 1136)))
where 1;
  • 追加新字段 

default:取默认值;

after:在哪个具体字段后添加新的字段;

alter table base_user_1 add column if not exists name Nullable(String);
alter table base_user_1 add column if not exists name Nullable(String) default 'china';
alter table base_user_1 add column if not exists name_1 Nullable(String) after tag;
  • 添加备注
alter table base_user_1 comment column if exists create_time '创建时间';
  •  修改数据类型

如果当前类型与期望类型不能兼容,则修改操作会失败,例如将String类型修改为IPv4类型是可行的,而尝试将String类型转为Uint类型就会出现错误;

alter table base_user_1 modify column id UInt32;

alter table yx_mt_01 modify column tag_1156 Nullable(Float32);
-- Nullable(UInt8)->Nullable(Float32);


alter table yx_mt_01 modify column tag_1153 Nullable(String);  
-- Nullable(UInt8)->Nullable(String);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值