美文网首页
HiveQL 数据定义:表的删除

HiveQL 数据定义:表的删除

作者: 无敌的肉包 | 来源:发表于2018-08-12 14:50 被阅读0次

DDL
• 删除表
• JDBC程序

删除表
DROP TABLE table_name

以下查询删除一个名为 employee的表:

hive> DROP TABLE IF EXISTS employee;

对于成功执行查询,能看到以下回应:

OK
Time taken: 5.3 seconds
hive>
JDBC程序

下面JDBC程序删除employee表。

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文件。使用下面的命令来编译和执行这个程序。
输出

Drop table successful

以下查询被用来验证表的列表:

hive> SHOW TABLES;
emp
ok
Time taken: 2.1 seconds
hive>

相关文章

网友评论

      本文标题:HiveQL 数据定义:表的删除

      本文链接:https://www.haomeiwen.com/subject/gbglbftx.html