DROP TABLE

說明

DROP TABLE 刪除表格,並從檔案系統中移除與表格關聯的目錄,如果表格不是 EXTERNAL 表格。如果表格不存在,它會擲回例外。

如果是外部表格,只有相關的元資料資訊會從 Metastore 資料庫中移除。

如果表格已快取,指令會取消快取表格及其所有依賴項。

語法

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;