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;