Hive 简明教程
Hive - Drop Table
本章介绍如何在 Hive 中删除数据表。在从 Hive Metastore 中删除数据表时,它将删除该数据表/列数据及其元数据。它可以是常规数据表(存储在 Metastore 中)或外部数据表(存储在本地文件系统中);与它们的类型无关,Hive 会将两者以相同的方式进行处理。
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;
以下查询删除名为 employee 的数据表:
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
以下 JDBC 程序删除 employee 数据表。
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;
public class HiveDropTable {
private static String driverName = "org.apache.hadoop.hive.jdbc.HiveDriver";
public 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();
}
}
在名为 HiveDropTable.java 的文件中保存程序。使用以下命令编译和执行此程序。
Save the program in a file named HiveDropTable.java. Use the following commands to compile and execute this program.
$ javac HiveDropTable.java
$ java HiveDropTable