Apache Phoenix:HBase之上的SQL工具[4]:Phoenix常用命令

栏目: 数据库 · 发布时间: 7年前

内容简介:作者:胡佳辉(Dennis)  时间:2019年1月1日  CSDN博客:查看帮助!help

Apache Phoenix:HBase之上的 SQL 工具[4]:Phoenix常用命令

作者:胡佳辉(Dennis)  时间:2019年1月1日  CSDN博客: https://blog.csdn.net/gobitan

查看帮助

!help

创建表

create table user(id integer not null primary key, i.first_name varchar,i.last_name varchar);

说明:

[1] 上面的命令创建了一个user表,包含一个id主键,一个列簇i,它包含两个列first_name和last_name;

[2] 如果不指定列簇,那么创建的时候会用'0'作为默认列簇。可以通过在创建表的时候,通过加上 "default_column_family=column_family_name"来设置,如下所示:

create table customer (id integer not null primary key, name varchar) default_column_family='a';

[3] 可以在"create table"后面加上if not exists来判断表是否已存在,如果存在就不再创建,如下所示:

create table if not exists user(id integer not null primary key);

[4] 在phoenix中,默认情况下,表名等会自动转换为大写,若要小写,使用双引号,如下所示:

create table "xiaoxie" (id integer not null primary key);

查看表

!desc user;

插入数据

upsert into user(id, i.first_name, i.last_name) values(1, 'Dennis', 'Hu');

upsert into user values(2, 'Mike', 'Lv');

说明:

[1] 如果插入相同的主键的记录,会自动覆盖之前的记录。因此,数据的更新也是用这个语句.

查询数据

select * from user;

select * from user where id = 2;

limit

group by

order by

having

and/or/in/like/between

join

删除数据

delete from user where id = 2;

查看所有表

!tables

修改表

alter table user add i.city varchar;

说明:

[1] 这里给user表的i列簇新增一列city;

删除表

drop table user;

说明:

[1] 删除时可以判断表是否存在,在"drop table"后面加上"if exists",如下所示:

drop table if exists user;

[2] 如果表上有view,那么可以在末尾加上"cascade"一起删除;

退出

!q

参考资料:

[1] https://phoenix.apache.org/language/index.html


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Domain-Driven Design

Domain-Driven Design

Eric Evans / Addison-Wesley Professional / 2003-8-30 / USD 74.99

"Eric Evans has written a fantastic book on how you can make the design of your software match your mental model of the problem domain you are addressing. "His book is very compatible with XP. It is n......一起来看看 《Domain-Driven Design》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

随机密码生成器
随机密码生成器

多种字符组合密码

HSV CMYK 转换工具
HSV CMYK 转换工具

HSV CMYK互换工具