HBase数据库表的创建

实验三 HBase分布式数据库操作与编程

1、HBase Shell数据库表创建

【实验内容】
根据以下关系型数据库表,使用HBase Shell设计并创建适宜的HBase数据表。
在这里插入图片描述

2、创建表以及插入学生信息数据

(1)、启动Hadoop
在这里插入图片描述
(2)、启动HBase
在这里插入图片描述
(3)、进入shell界面
在这里插入图片描述
(4)、创建表
在这里插入图片描述
(5)、插入数据(我是采用的学生的学号作为RowKey即行键,因此插入数据时不必在插入学生编号,同时课程建了三个列族,用于存储同一行键下的不同课程)
①新增学号为2015001的学生的所有信息

put 'StudentAndCourse','2015001','student:S_Name','Zhangsan'
put 'StudentAndCourse','2015001','student:S_Sex','male'
put 'StudentAndCourse','2015001','student:S_Age','23'
put 'StudentAndCourse','2015001','course1:C_No','123001'
put 'StudentAndCourse','2015001','course1:C_Name','Math'
put 'StudentAndCourse','2015001','course1:C_Credit','2.0'
put 'StudentAndCourse','2015001','course1:Score','86'
put 'StudentAndCourse' ,'2015001','course3:C_No','123003'
put 'StudentAndCourse' ,'2015001','course3:C_Name','English'
put 'StudentAndCourse' ,'2015001','course3:C_Credit','3.0'
put 'StudentAndCourse' ,'2015001','course3:Score','69'

②、新增学号为2015002的学生的所有信息

put 'StudentAndCourse' ,'2015002','student:S_Name','Mary'
put 'StudentAndCourse' ,'2015002','student:S_Sex','female'
put 'StudentAndCourse' ,'2015002','student:S_Age','22'
put 'StudentAndCourse' ,'2015002','course2:C_No','123002'
put 'StudentAndCourse' ,'2015002','course2:C_Name','Conputer Science'
put 'StudentAndCourse' ,'2015002','course2:Credit','5.0'
put "StudentAndCourse" ,'2015002','course2:Score','77'
put 'StudentAndCourse' ,'2015002','course3:C_No','123003'
put 'StudentAndCourse' ,'2015002','course3:C_Name','English'
put 'StudentAndCourse' ,'2015002','course3:Credit','3.0'
put 'StudentAndCourse' ,'2015002','course3:Score','99'

③、新增学号为2015003的学生的所有信息

put 'StudentAndCourse' ,'2015003','student:S_Name','Lisi'
put 'StudentAndCourse' ,'2015003','student:S_Sex','male'
put 'StudentAndCourse' ,'2015003','student:S_Age','24'
put 'StudentAndCourse' ,'2015003','course1:C_No','123001'
put 'StudentAndCourse' ,'2015003','course1:C_Name','Math'
put 'StudentAndCourse' ,'2015003','course1:C_Credit','2.0'
put 'StudentAndCourse' ,'2015003','course1:Score','98'
put 'StudentAndCourse' ,'2015003','course2:C_No','123002'
put 'StudentAndCourse' ,'2015003','course2:C_Name','Computer Science'
put 'StudentAndCourse' ,'2015003','course2:C_Credit','5.0'
put 'StudentAndCourse' ,'2015003','course2:Score','95'

3、查看表的数据

①、新增学号2015001的学生信息过后表的数据
在这里插入图片描述
②、新增学号为2015002的学生信息过后表的数据
在这里插入图片描述
③、学生信息全都新增过后表的数据
在这里插入图片描述
总的来说,在shell命令中插入数据还挺麻烦的,每次只能添加表的一行数据的一个列,也就是一个单元格的数据,如果向这种数据比较多的话,插入数据是比较费时间的。还有一个问题就是如果创建表的时候,对于课程不创建三个列族,而是创建一个列族的话,那么对于同一行键的不同选课,就比如Zhangsan选有课程Math与English,如何将Math与English存储在同一个列族下呢?

发布了5 篇原创文章 · 获赞 6 · 访问量 661

猜你喜欢

转载自blog.csdn.net/miss_bear/article/details/105421419