Table of contents
1.
Introduction
2.
Creating a table
2.1.
Key points:
3.
Listing a table
4.
Disabling a table
4.1.
disable
4.2.
is_disabled
4.3.
disable_all
5.
Enabling a table
5.1.
enable
5.2.
is_enabled
6.
Describe
7.
Alter
8.
Existence of a table
9.
Dropping a table
10.
FAQs
11.
Key takeaways
Last Updated: Mar 27, 2024

HBase Table Management

Author ANKIT KUMAR
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

There can be various operations on a table in HBase. We may need commands to create a table, describe a table, alter a table, display the list of tables present in HBase, enable and disable the table, and many more. Each of these operations has different commands. This article will discuss various such commands. We shall see the syntax, meaning, and example of each command.

Creating a table

Creating a table in HBase is as easy as creating a table in SQL. However, in the case of columns, we have column families in HBase, which in turn can have various qualifiers or attributes. It is also not necessary that each row will have the same column family qualifiers or attributes.

Syntax:
create 'table_name', 'column_family1', 'column_family2',....., 'column_family_n'

We use the create command to create a new table in HBase. Along with the table name, we also need to specify the column families in the table.

Example:
We want to create a team table with column families as players, staff, guides.

hbase (main) :002:0> create ‘team’, ‘players’, ‘staff’, ‘guides’

Key points:

  • We did not specify any qualifiers like player name, staff name, etc.
  • We did not specify the row key.
  • There are no data types.
  • HBase is case-sensitive. Therefore 'table' is not the same as 'Table.'

Listing a table

The list command is used to display the list of all the tables present in the HBase. So this can also be used to verify if the table is created or not.

Syntax:
list 

The syntax for listing the tables is very simple. We just need to use the word list.

Example:

hbase (main) :003:0> list

 

Disabling a table

disable

The table needs to be disabled first if we want to change its settings or delete the table. 

Syntax:
disable 'table_name'

Example:

hbase(main):025:0> disable 'mytable'

The above command will disable the table named mytable.

is_disabled

In order to ascertain whether a given table is disabled or not, we can use the is_disabled command.

Syntax:
is_disabled 'table_name'

Example:

hbase(main):030:0> is_disabled 'mytable'

It will display true if the table is disabled and false otherwise.

disable_all

This command is used to disable all such tables that match the given regex.

Syntax:
disable_all 'regex'

Example:

hbase(main):004:01> disable_all 'a*'

The above code will disable all the tables starting with the letter a.

Enabling a table

enable

The enable command is used to enable a table that has been disabled earlier.

Syntax:
enable ‘table_name’

Example:

hbase(main):005:0> enable 'mytable'

The above code will enable the "mytable" table again, which was disabled.

is_enabled

This command functions similarly to is_disabled. The is_enabled command is used to ascertain whether the given table is enabled or not. It returns true if it is enabled; otherwise, it returns false.

Syntax:
is_enabled 'table_name'

Example:

hbase(main):041:0> is_enabled 'mytable'

 

Describe

The describe command is used to get the description of the table. The descriptions include version, compression, blocksize, etc. Apart from the description, it also returns whether the table is enabled or disabled.

Syntax:
describe ‘table_name’

Example:

hbase(main):008:0> describe 'mytable'

 

Alter

The alter command is one of the most important commands of HBase. It is used to change or modify the attributes of an existing table. Suppose we want to add a new column family or delete an attribute from the column family. We can do this using the alter command.

Example:

hbase(main):005:0> alter 'mytable', {NAME=> 'columnfamily2'}

The above code will add another column family having the name columnfamily2.

Example:

hbase(main):006:0> alter 'mytable', {NAME => 'columnfamily2', METHOD => 'delete'}

The above code will delete the column family columnfamily2.

We can do various other operations on the table using the alter command like adding versions, etc. 

Existence of a table

The exists command is used to check whether the table exists in the database or not. It returns true if the table exists; otherwise, it will return false.

Syntax:
exits ‘table_name’

Example:

hbase(main):008:0> exists 'mytable'

 

Dropping a table

The drop command is used to delete the table permanently. However, it is necessary to first disable the table before we drop it. After dropping the table, we can use the exists command to check whether the table exists or not. If the table is deleted successfully, the exists command will return false.

Syntax:
drop ‘table_name’

Example:

hbase(main):010:0> disable 'mytable'
hbase(main):011:0> drop 'mytable'

 

FAQs

  1. Name some table management commands in HBase.
    create, list, disable, enable, describe, alter, exists, and drop.
     
  2. Which command is used to create a table in Hbase?
    create
     
  3. Which command displays all the tables in HBase?
    list
     
  4. What is the difference between enable and disable commands in HBase?
    disable command is used to disable the table, which is required in case we want to change the settings of the table or delete the table. The enable command enables the already disabled table.
     
  5. Which command is used to delete a table?
    drop 
     

Take this awesome course from coding ninjas.

Key takeaways

  • create, list, disable, enable, describe, alter, exists, and drop are some of the table management commands in HBase.
  • create command is used to create a table.
  • list command displays the list of all the tables in the HBase.
  • Alter command is used to modify the attributes of a given table. We can modify the column family schema.
  • The table must be disabled before we drop that table.
  • is_enabled command lets you know whether the table is enabled or not.
  • is_disabled command lets you know whether the table is disabled or not.

Never stop learning. Explore more here.

Happy learning!

Live masterclass