

{"id":17299,"date":"2018-06-17T04:20:03","date_gmt":"2018-06-17T04:20:03","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=17299"},"modified":"2018-06-17T04:20:03","modified_gmt":"2018-06-17T04:20:03","slug":"commands-in-hbase","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/","title":{"rendered":"Table Management Commands in HBase"},"content":{"rendered":"<p><span style=\"font-weight: 400\">Here, in this <strong>HBase<\/strong> article, we will learn all the Table Management commands in HBase. These HBase Commands are Create table, List table, Disable table, Enable table, Describe\u00a0&amp; Alter table, Exist table and Drop table. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we will see how to use these several <strong>Shell Commands<\/strong> in HBase using Java API. Moreover, we will discuss syntax &amp; example of Table Commands in HBase<\/span><\/p>\n<p>So, let&#8217;s explore Commands in HBase.<\/p>\n<h2>Creating a Table Using HBase Shell<\/h2>\n<h3>i. HBase Create Table<\/h3>\n<p><span style=\"font-weight: 400\">By using the create command in HBase, we can create a table. However, it is must to specify the table name and the Column Family name here. <\/span><br \/>\n<strong>A syntax for HBase Create Table commands in HBase<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">create \u2018&lt;table name&gt;\u2019,\u2019&lt;column family&gt;\u2019<\/pre>\n<p><strong>Example of HBase Create Table\u00a0<\/strong><br \/>\n<span style=\"font-weight: 400\">Here is an example of sample schema of a table named emp1. There are two column families in HBase of it: <\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">personal data<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">professional data<\/span><\/li>\n<\/ol>\n<table style=\"height: 75px\" width=\"326\">\n<tbody>\n<tr>\n<td><span style=\"font-weight: 400\">Row key<\/span><\/td>\n<td><span style=\"font-weight: 400\">personal data<\/span><\/td>\n<td><span style=\"font-weight: 400\">professional data<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400\">in HBase shell, we can create this table:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">hbase(main):002:0&gt; create 'emp1', 'personal data', 'professional data'<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Output<\/span><\/li>\n<\/ul>\n<p><b>0 row(s) in 1.1300 seconds<\/b><br \/>\n<b>=&gt; Hbase::Table &#8211; emp1<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>Verification<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">By using the HBase list command, we can verify whether the table is created.<\/span><br \/>\n<span style=\"font-weight: 400\">Below see the created emp1 table.<\/span><br \/>\n<b>hbase(main):002:0&gt; list<\/b><br \/>\n<b>TABLE <\/b><br \/>\n<b>emp1<\/b><br \/>\n<b>2 row(s) in 0.0340 seconds<\/b><\/p>\n<h3>ii.\u00a0Creating a Table Using Java API<\/h3>\n<p><span style=\"font-weight: 400\">Also, by using the createTable() method of HBaseAdmin class, we can create a table in HBase. Basically, it belongs to the org.apache.hadoop.hbase.client package. However, \u00a0to create a table in HBase using<strong> Java<\/strong> API, follow these steps.<\/span><\/p>\n<p><span style=\"font-weight: 400\"><strong>Step1:<\/strong> Instantiate <strong>HBaseAdmin<\/strong><\/span><\/p>\n<p><span style=\"font-weight: 400\">At first, instantiate the Configuration class and pass this instance to HBaseAdmin, because this class requires the Configuration object as a parameter:<\/span><br \/>\n<b>Configuration conf = HBaseConfiguration.create();<\/b><br \/>\n<b>HBaseAdmin admin = new HBaseAdmin(conf);<\/b><\/p>\n<p><span style=\"font-weight: 400\"><strong>Step2:<\/strong> Create TableDescriptor<\/span><\/p>\n<p><span style=\"font-weight: 400\">This class belongs to the org.apache.hadoop.hbase class. Basically, this container of table names and column families.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">\/\/creating table descriptor\nHTableDescriptor table = new HTableDescriptor(toBytes(\"Table name\"));\n\/\/creating column family descriptor\nHColumnDescriptor family = new HColumnDescriptor(toBytes(\"column family\"));\n\/\/adding coloumn family to HTable\ntable.addFamily(family);<\/pre>\n<p><span style=\"font-weight: 400\"><strong>Step 3:<\/strong> Execute through Admin<\/span><\/p>\n<p><span style=\"font-weight: 400\">We can execute the created table in Admin mode, by using the createTable() method of HBaseAdmin class.<\/span><br \/>\n<b>admin.createTable(table);<\/b><br \/>\n<span style=\"font-weight: 400\">To create a table via admin, here is the complete program.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import java.io.IOException;\nimport org.apache.hadoop.hbase.HBaseConfiguration;\nimport org.apache.hadoop.hbase.HColumnDescriptor;\nimport org.apache.hadoop.hbase.HTableDescriptor;\nimport org.apache.hadoop.hbase.client.HBaseAdmin;\nimport org.apache.hadoop.hbase.TableName;\nimport org.apache.hadoop.conf.Configuration;\npublic class CreateTable {\n  public static void main(String[] args) throws IOException {\n     \/\/ Instantiating configuration class\n     Configuration con = HBaseConfiguration.create();\n     \/\/ Instantiating HbaseAdmin class\n     HBaseAdmin admin = new HBaseAdmin(con);\n     \/\/ Instantiating table descriptor class\n     HTableDescriptor tableDescriptor = new\n     HTableDescriptor(TableName.valueOf(\"emp1\"));\n     \/\/ Adding column families to table descriptor\n     tableDescriptor.addFamily(new HColumnDescriptor(\"personal\"));\n     tableDescriptor.addFamily(new HColumnDescriptor(\"professional\"));\n     \/\/ Execute the table through admin\n     admin.createTable(tableDescriptor);\n     System.out.println(\" Table created \");\n  }\n}<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>To Compile and execute:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">$javac CreateTable.java\n$java CreateTable<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>Output:<\/strong><\/li>\n<\/ul>\n<p><b>Table created<\/b><\/p>\n<h2><span style=\"font-weight: 400\">Listing a Table Using HBase Shell<\/span><\/h2>\n<h3>i. HBase List Table<\/h3>\n<p><span style=\"font-weight: 400\">Basically, to list all the tables, we use the list commands in HBase. <\/span><br \/>\n<strong>A Syntax for List HBase :<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">hbase(main):001:0 &gt; list<\/pre>\n<p><span style=\"font-weight: 400\">This command will display the list of all the tables in HBase while we type this command and execute in HBase prompt:<\/span><br \/>\n<b>hbase(main):001:0&gt; list<\/b><br \/>\n<b>TABLE<\/b><br \/>\n<b>emp1<\/b><\/p>\n<p><span style=\"font-weight: 400\">Hence we can see a table named emp1.<\/span><\/p>\n<h3>ii.\u00a0Listing Tables Using Java API<\/h3>\n<p><span style=\"font-weight: 400\">By using Java API, get the list of tables from HBase, for that follow these steps:<\/span><\/p>\n<p><strong>Step 1<\/strong><br \/>\n<span style=\"font-weight: 400\">To get the list of all the tables in HBase, in the class HBaseAdmin we have a method called listTables().<\/span><br \/>\n<span style=\"font-weight: 400\"> Basically, this method returns an array of HTableDescriptor objects.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">\/\/creating a configuration object\nConfiguration conf = HBaseConfiguration.create();\n\/\/Creating HBaseAdmin object\nHBaseAdmin admin = new HBaseAdmin(conf);\n\/\/Getting all the list of tables using HBaseAdmin object\nHTableDescriptor[] tableDescriptor = admin.listTables();<\/pre>\n<p><strong>Step 2<\/strong><br \/>\n<span style=\"font-weight: 400\">Moreover, using the length variable of the HTableDescriptor class, we can get the length of the HTableDescriptor[] array. Also, using getNameAsString() method, \u00a0get the name of the tables from this object. So, using these run the \u2018for\u2019 loop to get the list of the tables in HBase.<\/span><\/p>\n<p><span style=\"font-weight: 400\">By using Java API, here is the program to list all the tables in HBase.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import java.io.IOException;\nimport org.apache.hadoop.conf.Configuration;\nimport org.apache.hadoop.hbase.HBaseConfiguration;\nimport org.apache.hadoop.hbase.HTableDescriptor;\nimport org.apache.hadoop.hbase.MasterNotRunningException;\nimport org.apache.hadoop.hbase.client.HBaseAdmin;\npublic class ListTables {\n  public static void main(String args[])throws MasterNotRunningException, IOException{\n     \/\/ Instantiating a configuration class\n     Configuration conf = HBaseConfiguration.create();\n     \/\/ Instantiating HBaseAdmin class\n     HBaseAdmin admin = new HBaseAdmin(conf);\n     \/\/ Getting all the list of tables using HBaseAdmin object\n     HTableDescriptor[] tableDescriptor = admin.listTables();\n     \/\/ printing all the table names.\n     for (int i=0; i&lt;tableDescriptor.length;i++ ){\n        System.out.println(tableDescriptor[i].getNameAsString());\n     }\n  }\n}<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">To Compile and execute:<\/span><\/li>\n<\/ul>\n<p><b>$javac ListTables.java<\/b><br \/>\n<b>$java ListTables<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400\"><strong>Output:<\/strong><\/li>\n<\/ul>\n<p><b>User<\/b><br \/>\n<b>emp1<\/b><\/p>\n<h2><span style=\"font-weight: 400\">Disabling a Table Using HBase Shell<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Basically, using the disable commands in HBase we need to first disable the table, to delete a table or change its settings.<\/span><\/p>\n<div id=\"attachment_18681\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Disabling-a-Table-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-18681\" class=\"wp-image-18681 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Disabling-a-Table-01.jpg\" alt=\"Commands in HBase\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Disabling-a-Table-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Disabling-a-Table-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Disabling-a-Table-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Disabling-a-Table-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Disabling-a-Table-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-18681\" class=\"wp-caption-text\">Disabling a Table Using HBase Shell<\/p><\/div>\n<h3>i. HBase Disable Table<\/h3>\n<p><strong>A Syntax for Disabling a Table<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">disable \u2018emp1\u2019<\/pre>\n<p><strong>b. Example for Disabling a Table<\/strong><\/p>\n<p><span style=\"font-weight: 400\">Below example explains to disable a table:<\/span><br \/>\n<b>hbase(main):025:0&gt; disable &#8217;emp1&#8242;<\/b><br \/>\n<b>0 row(s) in 1.2760 seconds<\/b><\/p>\n<p><strong>c. Verification<\/strong><\/p>\n<p><span style=\"font-weight: 400\">However, we can still sense its existence through the list and exists commands, after disabling the table. Although, we cannot scan it. It will display error:<\/span><br \/>\n<b>hbase(main):028:0&gt; scan &#8217;emp1&#8242;<\/b><br \/>\n<b>ROW \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0COLUMN + CELL<\/b><br \/>\n<b>ERROR: emp1 is disabled.<\/b><\/p>\n<h3><span style=\"font-weight: 400\">ii. is_disabled<\/span><\/h3>\n<p><span style=\"font-weight: 400\">To find whether a table is disabled, we can use this command in HBase.<\/span><br \/>\n<strong>A Syntax for\u00a0is_disabled<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">hbase&gt; is_disabled 'table name'<\/pre>\n<p><strong>For Example<\/strong><br \/>\n<span style=\"font-weight: 400\">It verifies whether the table named emp1 is disabled. So, to check that it is disabled, make sure it will return true and it will return false, \u00a0if not.<\/span><br \/>\n<b>hbase(main):031:0&gt; is_disabled &#8217;emp1&#8242;<\/b><br \/>\n<b>true<\/b><br \/>\n<b>0 row(s) in 0.0440 seconds<\/b><\/p>\n<h3><span style=\"font-weight: 400\">iii. disable_all<\/span><\/h3>\n<p><span style=\"font-weight: 400\">To disable all the tables matching the given regex, we can use this commands in HBase.<\/span><br \/>\n<strong>A Syntax for disable_all:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">hbase&gt; disable_all 'r.*'<\/pre>\n<h3>iv. Disable a Table Using Java API<\/h3>\n<p><span style=\"font-weight: 400\">Here are some commands belong to the HBaseAdmin class, like<\/span><b> isTableDisabled() method &#8211; <\/b><span style=\"font-weight: 400\">to verify whether a table is disabled, <\/span><b>disableTable() method-<\/b><span style=\"font-weight: 400\"> to disable a table. \u00a0To disable a table, follow these steps:<\/span><\/p>\n<p><strong>Step 1<\/strong><br \/>\n<span style=\"font-weight: 400\">Instantiate HBaseAdmin class:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">\/\/ Creating configuration object\nConfiguration conf = HBaseConfiguration.create();\n\/\/ Creating HBaseAdmin object\nHBaseAdmin admin = new HBaseAdmin(conf);\n<\/pre>\n<p><strong><span style=\"font-family: Verdana, Geneva, sans-serif\">Step 2<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">Then using isTableDisabled() method , verify whether the table is disabled:<\/span><br \/>\n<b>Boolean b = admin.isTableDisabled(&#8220;emp1&#8221;);<\/b><\/p>\n<p><strong>Step 3<\/strong><br \/>\n<span style=\"font-weight: 400\">disable it, if the table is not disabled:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">if(!b){\n  admin.disableTable(\"emp1\");\n  System.out.println(\"Table disabled\");\n}<\/pre>\n<p><span style=\"font-weight: 400\">To verify whether the table is disabled; if not, how to disable it, \u00a0is the complete program.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import java.io.IOException;\nimport org.apache.hadoop.conf.Configuration;\nimport org.apache.hadoop.hbase.HBaseConfiguration;\nimport org.apache.hadoop.hbase.MasterNotRunningException;\nimport org.apache.hadoop.hbase.client.HBaseAdmin;\npublic class DisableTable{\n  public static void main(String args[]) throws MasterNotRunningException, IOException{\n     \/\/ Instantiating configuration class\n     Configuration conf = HBaseConfiguration.create();\n     \/\/ Instantiating HBaseAdmin class\n     HBaseAdmin admin = new HBaseAdmin(conf);\n     \/\/ Verifying weather the table is disabled\n     Boolean bool = admin.isTableDisabled(\"emp1\");\n     System.out.println(bool);\n     \/\/ Disabling the table using HBaseAdmin object\n     if(!bool){\n        admin.disableTable(\"emp1\");\n        System.out.println(\"Table disabled\");\n     }\n  }\n}<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>To compile and execute:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">$javac DisableTable.java\n$java DsiableTable<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>Output:<\/strong><\/li>\n<\/ul>\n<p><b>false<\/b><br \/>\n<b>Table disabled<\/b><\/p>\n<h2><span style=\"font-weight: 400\">Enabling a Table Using HBase Shell<\/span><\/h2>\n<div id=\"attachment_18689\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Enabling-a-Table-01-3.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-18689\" class=\"wp-image-18689 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Enabling-a-Table-01-3.jpg\" alt=\"Commands in HBase\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Enabling-a-Table-01-3.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Enabling-a-Table-01-3-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Enabling-a-Table-01-3-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Enabling-a-Table-01-3-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/Enabling-a-Table-01-3-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-18689\" class=\"wp-caption-text\">Enabling a Table<\/p><\/div>\n<h3>i. HBase Enable Table<\/h3>\n<p><strong>A Syntax for HBase Enable Table:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">enable \u2018emp1\u2019<\/pre>\n<p><strong>Example<\/strong><br \/>\n<span style=\"font-weight: 400\">To enable a table, here is an example.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">hbase(main):005:0&gt; enable 'emp1'\n0 row(s) in 0.4580 seconds<\/pre>\n<h3>ii.\u00a0is_enabled<\/h3>\n<p><span style=\"font-weight: 400\">In order to find whether a table is enabled, follow this HBase command.<\/span><br \/>\n<strong>A Syntax for is_enabled:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">hbase&gt; is_enabled 'table name'<\/pre>\n<p><span style=\"font-weight: 400\">Whether the table named emp1 is enabled, use this following code to verify. Basically, \u00a0it will return true, if it is enabled, and it will return false, if not.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">hbase(main):031:0&gt; is_enabled 'emp1'\ntrue\n0 row(s) in 0.0440 seconds<\/pre>\n<h3>iii.\u00a0Enable a Table Using Java API<\/h3>\n<p><span style=\"font-weight: 400\">To verify whether a table is enabled, isTableEnabled() method is used; and to enable a table, enableTable() method is used. These methods belong to HBaseAdmin class. Follow the steps given below to enable a table.<\/span><\/p>\n<p><strong>Step1<\/strong><br \/>\n<span style=\"font-weight: 400\">Instantiate HBaseAdmin:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">\/\/ Creating configuration object\nConfiguration conf = HBaseConfiguration.create();\n\/\/ Creating HBaseAdmin object\nHBaseAdmin admin = new HBaseAdmin(conf);<\/pre>\n<p><strong>Step 2<\/strong><br \/>\n<span style=\"font-weight: 400\">Now, by using isTableEnabled() method, verify whether the table is enabled:<\/span><br \/>\n<b>Boolean bool = admin.isTableEnabled(&#8220;emp1&#8221;);<\/b><\/p>\n<p><strong>Step 3<\/strong><br \/>\n<span style=\"font-weight: 400\">Disable it, if the table is not disabled:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">if(!bool){\n  admin.enableTable(\"emp1\");\n  System.out.println(\"Table enabled\");\n}<\/pre>\n<p><span style=\"font-weight: 400\">To verify whether the table is enabled and if it is not, then how to enable it, here is the program.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import java.io.IOException;\nimport org.apache.hadoop.conf.Configuration;\nimport org.apache.hadoop.hbase.HBaseConfiguration;\nimport org.apache.hadoop.hbase.MasterNotRunningException;\nimport org.apache.hadoop.hbase.client.HBaseAdmin;\npublic class EnableTable{\n  public static void main(String args[]) throws MasterNotRunningException, IOException{\n     \/\/ Instantiating configuration class\n     Configuration conf = HBaseConfiguration.create();\n     \/\/ Instantiating HBaseAdmin class\n     HBaseAdmin admin = new HBaseAdmin(conf);\n     \/\/ Here, verifying whether the table is disabled\n     Boolean bool = admin.isTableEnabled(\"emp1\");\n     System.out.println(bool);\n     \/\/ Using HBaseAdmin object Enabling the table\n     if(!bool){\n        admin.enableTable(\"emp1\");\n        System.out.println(\"Table Enabled\");\n     }\n  }\n}<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>To Compile and execute:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">$javac EnableTable.java\n$java EnableTable<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>Output:<\/strong><\/li>\n<\/ul>\n<p><b>false<\/b><br \/>\n<b>Table Enabled<\/b><\/p>\n<h2><span style=\"font-weight: 400\">HBase Describe a Table Using Shell\u00a0<\/span><\/h2>\n<p><span style=\"font-weight: 400\">To get the description of the table in return, follow this HBase command. <\/span><br \/>\n<strong>A Syntax for Describe Table:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">hbase&gt; describe 'table name'<\/pre>\n<h2>HBase Alter Table<\/h2>\n<p><span style=\"font-weight: 400\">To make changes to an existing table, we use this Alter command. Basically, there are several operations like the set and delete table scope operators, change the maximum number of cells of a column family, and delete a column family from a table are possible with this command in HBase.<\/span><\/p>\n<h2><span style=\"font-weight: 400\">Existence of Table using HBase Shell<\/span><\/h2>\n<p>By using the exists HBase command, we can verify the existence of a table.<\/p>\n<h3>i. HBase Exist<\/h3>\n<p><strong>Example of existence:<\/strong><br \/>\n<b>hbase(main):024:0&gt; exists &#8217;emp&#8217;<\/b><br \/>\n<b>Table emp does exist<\/b><br \/>\n<b>0 row(s) in 0.0750 seconds<\/b><br \/>\n<b>==================================================================<\/b><br \/>\n<b>hbase(main):015:0&gt; exists &#8216;student&#8217;<\/b><br \/>\n<b>Table student does not exist<\/b><br \/>\n<b>0 row(s) in 0.0480 seconds<\/b><\/p>\n<h3>ii. Verifying the Existence of Table Using Java API<\/h3>\n<p><span style=\"font-weight: 400\">Also, using one of the HBaseAdmin class method the tableExists(), we can verify the existence of a table in HBase. So, to verify the existence of a table in HBase, follow the steps:<\/span><br \/>\n<strong>Step 1<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">Instantiate the HBaseAdimn class\n\/\/ Instantiating configuration object\nConfiguration conf = HBaseConfiguration.create();\n\/\/ Instantiating HBaseAdmin class\nHBaseAdmin admin = new HBaseAdmin(conf);<\/pre>\n<p><strong><span style=\"font-family: Verdana, Geneva, sans-serif\">Step 2<\/span><\/strong><br \/>\n<span style=\"font-weight: 400\">Then using the tableExists( ) method verify the existence of the table.<\/span><br \/>\n<span style=\"font-weight: 400\">To test the existence of a table in HBase using Java API<\/span><span style=\"font-weight: 400\"> here is <\/span><span style=\"font-weight: 400\">the java program.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import java.io.IOException;\nimport org.apache.hadoop.hbase.HBaseConfiguration;\nimport org.apache.hadoop.conf.Configuration;\nimport org.apache.hadoop.hbase.client.HBaseAdmin;\npublic class TableExists{\n  public static void main(String args[])throws IOException{\n     \/\/ Instantiating configuration class\n     Configuration conf = HBaseConfiguration.create();\n     \/\/ Instantiating HBaseAdmin class\n     HBaseAdmin admin = new HBaseAdmin(conf);\n     \/\/ Verifying the existance of the table\n     boolean bool = admin.tableExists(\"emp\");\n     System.out.println( bool);\n  }\n}<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>To compile and execute:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">$javac TableExists.java\n$java TableExists<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>Output:<\/strong><\/li>\n<\/ul>\n<p><b>True<\/b><\/p>\n<h2><span style=\"font-weight: 400\">Dropping a Table using HBase Shell<\/span><\/h2>\n<p><span style=\"font-weight: 400\">We can delete a table, by using the drop commands in HBase. Make sure, we have to disable it, before dropping a table.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">hbase(main):018:0&gt; disable 'emp'\n0 row(s) in 1.4580 seconds\nhbase(main):019:0&gt; drop 'emp'\n0 row(s) in 0.3060 seconds<\/pre>\n<p><span style=\"font-family: Verdana, Geneva, sans-serif\">Now, using the exists HBase command, verify whether the table is deleted.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">hbase(main):020:07gt; exists 'emp'\nTable emp does not exist\n0 row(s) in 0.0730 seconds<\/pre>\n<h3>i.\u00a0drop_all<\/h3>\n<p><span style=\"font-weight: 400\">Basically, in order to drop the tables which are matching the \u201cregex\u201d that is given in the command, we use this commands in HBase. <\/span><br \/>\n<strong>A Syntax for drop_all:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">hbase&gt; drop_all \u2018t.*\u2019<\/pre>\n<h2>Deleting a Table Using Java API<\/h2>\n<p><span style=\"font-weight: 400\">Also, using one of the HBaseAdmin class method &#8220;the deleteTable() method&#8221;, we can delete a table. So, \u00a0to delete a table using Java API, follow these steps:<\/span><br \/>\n<strong>Step 1<\/strong><br \/>\n<span style=\"font-weight: 400\">Instantiate the HBaseAdmin class.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">\/\/ creating a configuration object\nConfiguration conf = HBaseConfiguration.create();\n\/\/ Creating HBaseAdmin object\nHBaseAdmin admin = new HBaseAdmin(conf);<\/pre>\n<p><strong>Step 2<\/strong><br \/>\n<span style=\"font-weight: 400\">By using the disableTable() method of the HBaseAdmin class, disable the table.<\/span><br \/>\n<b>admin.disableTable(&#8220;emp1&#8221;);<\/b><\/p>\n<p><strong>Step 3<\/strong><br \/>\n<span style=\"font-weight: 400\">Then using the deleteTable() method of the HBaseAdmin class, \u00a0delete the table.<\/span><br \/>\n<b>admin.deleteTable(&#8220;emp12&#8221;);<\/b><\/p>\n<p><span style=\"font-weight: 400\">So, to delete a table in HBase here is the complete Java program.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">import java.io.IOException;\nimport org.apache.hadoop.hbase.HBaseConfiguration;\nimport org.apache.hadoop.conf.Configuration;\nimport org.apache.hadoop.hbase.client.HBaseAdmin;\npublic class DeleteTable {\n  public static void main(String[] args) throws IOException {\n     \/\/ Instantiating configuration class\n     Configuration conf = HBaseConfiguration.create();\n     \/\/ Instantiating HBaseAdmin class\n     HBaseAdmin admin = new HBaseAdmin(conf);\n     \/\/ disabling table named emp\n     admin.disableTable(\"emp12\");\n     \/\/ Deleting emp\n     admin.deleteTable(\"emp12\");\n     System.out.println(\"Table deleted\");\n  }\n}<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>To Compile and execute:<\/strong><\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">$javac DeleteTable.java\n$java DeleteTable<\/pre>\n<ul>\n<li style=\"font-weight: 400\"><strong>Output:<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Table deleted<\/span><br \/>\nSo, this was all about Table Commands in HBase. Hope you like our explanation.<\/p>\n<h2><span style=\"font-weight: 400\">Conclusion: HBase Commands<\/span><\/h2>\n<p><span style=\"font-weight: 400\">Hence, in this HBase Commands tutorial, we have seen all the commands in\u00a0HBase like Create, List, Disable, enable, describe\u00a0&amp; Alter, exist, drop table in detail. Moreover, we discussed syntax and example of HBase Commands. However, if any doubt occurs, regarding these Commands in HBase, feel free to ask.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here, in this HBase article, we will learn all the Table Management commands in HBase. These HBase Commands are Create table, List table, Disable table, Enable table, Describe\u00a0&amp; Alter table, Exist table and Drop&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":18665,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[2676,3020,3089,3773,3933,4074,4136,4456,5405,5409,5486,5491,8315,14136],"class_list":["post-17299","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hbase","tag-commands-in-hbase","tag-cpmmands-in-hbase","tag-create-table","tag-describe-and-alter","tag-disable","tag-drop-table","tag-enable","tag-exist","tag-hbase-commands","tag-hbase-commands-create","tag-hbase-table","tag-hbase-tutorial","tag-list","tag-table-commands-in-hbase"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Table Management Commands in HBase - DataFlair<\/title>\n<meta name=\"description\" content=\"Table Commands in HBase, HBase create table,drop,disable,enable,list,alter,exist, delete table HBase commands, HBase shell commands, commands using Java API\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Table Management Commands in HBase - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Table Commands in HBase, HBase create table,drop,disable,enable,list,alter,exist, delete table HBase commands, HBase shell commands, commands using Java API\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-06-17T04:20:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/HBase-Commands-01-2.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Table Management Commands in HBase - DataFlair","description":"Table Commands in HBase, HBase create table,drop,disable,enable,list,alter,exist, delete table HBase commands, HBase shell commands, commands using Java API","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/","og_locale":"en_US","og_type":"article","og_title":"Table Management Commands in HBase - DataFlair","og_description":"Table Commands in HBase, HBase create table,drop,disable,enable,list,alter,exist, delete table HBase commands, HBase shell commands, commands using Java API","og_url":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-06-17T04:20:03+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/HBase-Commands-01-2.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"Table Management Commands in HBase","datePublished":"2018-06-17T04:20:03+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/"},"wordCount":1461,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/HBase-Commands-01-2.jpg","keywords":["Commands in HBase","cpmmands in HBase","Create Table","describe and Alter","Disable","Drop Table","enable","exist","hbase commands","HBase Commands: Create","HBase Table","hbase tutorial","List","Table commands in HBase"],"articleSection":["HBase Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/commands-in-hbase\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/","url":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/","name":"Table Management Commands in HBase - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/HBase-Commands-01-2.jpg","datePublished":"2018-06-17T04:20:03+00:00","description":"Table Commands in HBase, HBase create table,drop,disable,enable,list,alter,exist, delete table HBase commands, HBase shell commands, commands using Java API","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/commands-in-hbase\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/HBase-Commands-01-2.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/06\/HBase-Commands-01-2.jpg","width":1200,"height":628,"caption":"Table Management Commands in HBase"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/commands-in-hbase\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"HBase Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/hbase\/"},{"@type":"ListItem","position":3,"name":"Table Management Commands in HBase"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/17299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=17299"}],"version-history":[{"count":0,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/17299\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/18665"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=17299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=17299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=17299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}