Hive Tutorial
HiveQL
Hive Useful Resources
Selected Reading
- Hive - Views And Indexes
- Hive - Built-In Functions
- Hive - Built-In Operators
- Hive - Partitioning
- Hive - Drop Table
- Hive - Alter Table
- Hive - Create Table
- Hive - Drop Database
- Hive - Create Database
- Hive - Data Types
- Hive - Installation
- Hive - Introduction
- Hive - Home
HiveQL
Hive Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Hive - Drop Table
Hive - Drop Table
This chapter describes how to drop a table in Hive. When you drop a table from Hive Metastore, it removes the table/column data and their metadata. It can be a normal table (stored in Metastore) or an external table (stored in local file system); Hive treats both in the same manner, irrespective of their types.
Drop Table Statement
The syntax is as follows:
DROP TABLE [IF EXISTS] table_name;
The following query drops a table named employee:
hive> DROP TABLE IF EXISTS employee;
On successful execution of the query, you get to see the following response:
OK Time taken: 5.3 seconds hive>
JDBC Program
The following JDBC program drops the employee table.
import java.sql.SQLException; import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import java.sql.DriverManager; pubpc class HiveDropTable { private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver"; pubpc static void main(String[] args) throws SQLException { // Register driver and create driver instance Class.forName(driverName); // get connection Connection con = DriverManager.getConnection("jdbc:hive://localhost:10000/userdb", "", ""); // create statement Statement stmt = con.createStatement(); // execute statement stmt.executeQuery("DROP TABLE IF EXISTS employee;"); System.out.println("Drop table successful."); con.close(); } }
Save the program in a file named HiveDropTable.java. Use the following commands to compile and execute this program.
$ javac HiveDropTable.java $ java HiveDropTable
Output:
Drop table successful
The following query is used to verify the pst of tables:
hive> SHOW TABLES; emp ok Time taken: 2.1 seconds hive>Advertisements