The set of HBase basic operations are referred to as CRUD operations. i.e. create, read, update, delete/drop operations. The HBase drop command is used to drop or delete table from HBase. In this article, we will check drop HBase tables using shell commands and some commonly used examples.
Drop HBase Tables using shell Commands
In order to drop or delete the table present in HBase, first we have to disable it using ‘disable <table name>’ command. There are two commands available to drop or delete HBase tables: ‘drop’ and ‘drop_all’.
HBase Drop Table Syntax
Below are the syntax for drop and drop_all commands:
drop <table name>drop_all <"regex">
HBase Drop Tables Examples
To demonstrate the disable and drop or delete command, we will create the sample table and drop it. Below are some of the drop and drop_all examples.
Dropping enabled Tables
You cannot drop or delete table which is in enable status. HBase shell will throw an error if you try to drop table without disabling it. Below is the error message for your reference:
hbase(main):019:0> drop 'test_table' ERROR: Table test_table is enabled. Disable it first. Here is some help for this command: Drop the named table. Table must first be disabled: hbase> drop 't1' hbase> drop 'ns1:t1'
HBase Drop Table Example
As mentioned earlier you must disable the table to drop or delete it.
hbase(main):020:0> disable 'test_table' 0 row(s) in 2.5110 seconds hbase(main):021:0> drop 'test_table' 0 row(s) in 1.2870 seconds
Use HBase exists command to verify if drop command is executed successfully.
hbase(main):022:0> exists 'test_table' Table test_table does not exist 0 row(s) in 0.0060 seconds
HBase Drop Table if Exists
Below example demonstrates drop table if exists scenario. Use exists command to check if table is exists then create table
hbase(main):022:0> exists 'test_table' Table test_table does not exist 0 row(s) in 0.0060 seconds hbase(main):023:0> create 'test_table', 'colFam1' 0 row(s) in 2.3430 seconds => Hbase::Table - test_table
Hbase drop_all command Examples
Below example demonstrates dropping all tables that matches the regular expression patterns. You must disable all the tables using HBase ‘disable_all’ command then drop_all command would work as expected.
hbase(main):026:0> disable_all 'test.*' test_table Disable the above 1 tables (y/n)? y 1 tables successfully disabled hbase(main):027:0> drop_all 'test.*' test_table Drop the above 1 tables (y/n)? y 1 tables successfully dropped
Read:
- Commonly used General Hbase Shell Commands
- Insert data using HBase shell put Command and Examples
- Read HBase Table using HBase shell get Command
- Hadoop HDFS Architecture Introduction and Design
- Create Tables using HBase Shell
- Official Apache HBase documentation
- Commonly used General Hbase Shell Commands