Dropping a Table using HBase Shell
Using the drop command, you can delete a table. Before dropping a table, you have to disable it.
hbase> disable 'emp' 0 row(s) in 1.2530 seconds hbase> drop 'emp' 0 row(s) in 0.4045 seconds
Verify whether the table is deleted using the exists command.
hbase> exists 'emp' Table emp does not exist 0 row(s) in 0.0842 seconds
drop_all
This command is used to drop the tables matching the “regex” given in the command. Its syntax is as follows
hbase> drop_all ‘a.*’
Note
Before dropping a table, you must disable it.
Example
Assume there are tables named Ashok, Ashwin, Aslam, Asha, and Ashwini.
hbase> list ashok ashwin aslam asha ashwini 5 row(s) in 0.0160 seconds
All these tables start with the letters as. First of all, let us disable all these tables using the disable_all command as shown below.
hbase> disable_all 'as.*' ashok ashwin aslam asha ashwini Disable the above 5 tables (y/n)? y 5 tables successfully disabled
package com.ashok.hbase; import java.io.IOException; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.MasterNotRunningException; import org.apache.hadoop.hbase.client.HBaseAdmin; /** * * @author ashok.mariyala * */ public class DropTable { public static void main(String args[]) throws MasterNotRunningException, IOException{ // Instantiating configuration class Configuration conf = HBaseConfiguration.create(); // Instantiating HBaseAdmin class HBaseAdmin admin = new HBaseAdmin(conf); // Verifying weather the table is disabled Boolean bool = admin.isTableDisabled("emp"); System.out.println(bool); // Delete the table using HBaseAdmin object if(!bool){ admin.deleteTable("emp"); System.out.println("Successfully Dropped Table"); } } }
Dropping a Table