HBase - Create Table

Creating a Table using HBase Shell

You can create a table using the create command, here you must specify the table name and the Column Family name. The syntax to create a table in HBase shell is shown below.

create ‘<table name>’,’<column family>’

Example

Given below is a sample schema of a table named emp. It has two column families: “personal data” and “professional data”.

Row key

personal data

professional data

You can create this table in HBase shell as shown below.

hbase(main):002:0> create 'emp', 'personal data', 'professional data'

And it will give you the following output.

0 row(s) in 1.1300 seconds
=> Hbase::Table - emp

Verification

You can verify whether the table is created using the list command as shown below. Here you can observe the created emp table.

hbase(main):002:0> list
TABLE
emp
2 row(s) in 0.0340 seconds

Creating a Table Using java API

You can create a table in HBase using the createTable() method of HBaseAdmin class. This class belongs to the org.apache.hadoop.hbase.client package. Given below are the steps to create a table in HBase using java API.

Step1: Instantiate HBaseAdmin

This class requires the Configuration object as a parameter, therefore initially instantiate the Configuration class and pass this instance to HBaseAdmin.