DROP TABLE
適用於: Databricks SQL Databricks Runtime
刪除資料表,並在數據表不是 EXTERNAL
數據表時,從檔案系統中移除與數據表相關聯的目錄。 如果數據表不存在,則會擲回例外狀況。
若要卸除數據表,您必須是數據表的擁有者,或是數據表所在的架構、目錄或中繼存放區擁有者。
如果是外部數據表,則只會從中繼存放區架構中移除相關聯的元數據資訊。
參考數據表的任何外鍵條件約束也會卸除。
如果快取數據表,命令會取消快取數據表及其所有相依專案。
注意
從 Unity 目錄卸除受控數據表時,其基礎數據會在 30 天內從您的雲端租用戶中刪除。
語法
DROP TABLE [ IF EXISTS ] table_name
參數
IF EXISTS
如果指定,當數據表不存在時,不會 擲回任何TABLE_OR_VIEW_NOT_FOUND 錯誤。
-
要卸除之數據表的名稱。 名稱不得包含 時態規格。 如果找不到數據表,Azure Databricks 就會 引發TABLE_OR_VIEW_NOT_FOUND 錯誤。
範例
-- Assumes a table named `employeetable` exists.
> DROP TABLE employeetable;
-- Assumes a table named `employeetable` exists in the `userdb` schema
> DROP TABLE userdb.employeetable;
-- Assumes a table named `employeetable` does not exist.
-- Throws TABLE_OR_VIEW_NOT_FOUND
> DROP TABLE employeetable;
Error: TABLE_OR_VIEW_NOT_FOUND
-- Assumes a table named `employeetable` does not exist,Try with IF EXISTS
-- this time it will not throw exception
> DROP TABLE IF EXISTS employeetable;