DROP TABLE
說明
DROP TABLE
刪除表格,並從檔案系統中移除與表格關聯的目錄,如果表格不是 EXTERNAL
表格。如果表格不存在,它會擲回例外。
如果是外部表格,只有相關的元資料資訊會從 Metastore 資料庫中移除。
如果表格已快取,指令會取消快取表格及其所有依賴項。
語法
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;