DROP TABLE
描述
DROP TABLE
删除表,并从文件系统中移除与该表关联的目录,如果该表不是 EXTERNAL
表。 如果该表不存在,则抛出异常。
如果是外部表,则只会从元数据存储数据库中删除相关的元数据信息。
如果该表被缓存,则该命令会取消缓存该表及其所有依赖项。
语法
DROP TABLE [ IF EXISTS ] table_identifier [ PURGE ]
参数
-
IF EXISTS
如果指定,当表不存在时,不会抛出异常。
-
table_identifier
指定要删除的表名。表名可以选择性地用数据库名称进行限定。
语法:
[ database_name. ] table_name
-
PURGE
如果指定,则在删除表时完全清除该表,跳过回收站(注意:PURGE 在 Hive Metastore 0.14.0 及更高版本中可用)。
示例
-- Assumes a table named `employeetable` exists.
DROP TABLE employeetable;
-- Assumes a table named `employeetable` exists in the `userdb` database
DROP TABLE userdb.employeetable;
-- Assumes a table named `employeetable` does not exist.
-- Throws exception
DROP TABLE employeetable;
Error: org.apache.spark.sql.AnalysisException: Table or view not found: employeetable;
(state=,code=0)
-- Assumes a table named `employeetable` does not exist,Try with IF EXISTS
-- this time it will not throw exception
DROP TABLE IF EXISTS employeetable;
-- Completely purge the table skipping trash.
DROP TABLE employeetable PURGE;