Bagikan melalui


DROP TABLE

Berlaku untuk:centang ditandai ya Databricks SQL centang ditandai ya Databricks Runtime

Menghapus tabel dan menghapus direktori yang terkait dengan tabel dari sistem file jika tabel bukan EXTERNAL tabel. Pengecualian terjadi jika tabel tidak ada. Untuk menghilangkan tabel, Anda harus memiliki hak istimewa MANAGE pada tabel, menjadi pemiliknya, atau pemilik skema, katalog, atau metastore tempat tabel berada.

Dalam kasus tabel eksternal, hanya informasi metadata terkait yang dihapus dari skema metastore.

Setiap batasan kunci asing yang mereferensikan tabel juga dihilangkan.

Jika tabel di-cache, perintah akan menghapus cache tabel dan semua dependennya.

Catatan

Tabel dihapus dalam waktu 7 hingga 30 hari. Katalog Unity mendukung UNDROP TABLE perintah untuk memulihkan tabel terkelola yang dihilangkan selama 7 hari. Setelah 7 hari, data dasar ditandai untuk dihapus dari penyewa cloud Anda selama operasi pemeliharaan tabel rutin.

Sintaks

DROP [ TEMPORARY ] TABLE [ IF EXISTS ] table_name [ FORCE ]

Pengaturan

Contoh

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

-- Creates and drops a temporary table
> CREATE TEMPORARY TABLE scratchpad(txt STRING);
> DROP TEMPORARY TABLE scratchpad;