共用方式為


DROP TABLE

適用於:已勾選「是」Databricks SQL 已勾選「是」Databricks Runtime

刪除資料表,並在數據表不是 EXTERNAL 數據表時,從檔案系統中移除與數據表相關聯的目錄。 如果資料表不存在,則會拋出例外狀況。 若要卸除數據表,您必須擁有該數據表的 MANAGE 許可權,或是成為該數據表的擁有者,或者是該數據表所在的架構、目錄或中繼存放區的擁有者。

在外部數據表的情況下,只會從中繼存放區架構中移除相關聯的元數據資訊。

參考資料表的任何外鍵約束也會被刪除。

如果表格已被快取,則命令會取消快取該表格及其所有相依項目。

注意

數據表會在 7 到 30 天內刪除。 Unity 目錄支援 UNDROP TABLE 命令,可以在 7 天內還原已刪除的受控數據表。 7 天後,底層數據會在一般數據表維護作業期間標示為要從您的雲端租用戶中刪除。

語法

DROP TABLE [ IF EXISTS ] table_name [ FORCE ]

參數

範例

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

-- Assumes a table named `employeetable` exists and has a shallow clone.
-- Throws CANNOT_DROP_BASE_TABLE_REFERENCED_BY_SHALLOW_CLONE
> DROP TABLE employeetable;
  Error: CANNOT_DROP_BASE_TABLE_REFERENCED_BY_SHALLOW_CLONE

-- Assumes a table named `employeetable` exists and has a shallow clone.
-- Drops base table, but shallow clones referencing this base table will no longer work
> DROP TABLE employeetable FORCE;