DROP TABLE

描述

DROP TABLE 删除表,并从文件系统中移除与该表关联的目录,如果该表不是 EXTERNAL 表。 如果该表不存在,则抛出异常。

如果是外部表,则只会从元数据存储数据库中删除相关的元数据信息。

如果该表被缓存,则该命令会取消缓存该表及其所有依赖项。

语法

DROP TABLE [ IF EXISTS ] table_identifier [ PURGE ]

参数

示例

-- 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;