DROP TABLE

Gäller för:markerad ja Databricks SQL markerad ja Databricks Runtime

Tar bort tabellen och tar bort katalogen som är associerad med tabellen från filsystemet om tabellen inte är en EXTERNAL tabell. Ett undantag utlöses om tabellen inte finns. Om du vill släppa en tabell måste du ha MANAGE behörighet i tabellen, vara dess ägare eller ägaren av schemat, katalogen eller metaarkivet som tabellen finns i.

När det gäller en extern tabell tas endast den associerade metadatainformationen bort från metaarkivschemat.

Begränsningar för främmande nyckel som refererar till tabellen tas också bort.

Om tabellen cachelagras rensar kommandot tabellen och alla dess beroenden.

Anteckning

Tabeller tas bort inom 7 till 30 dagar. Unity Catalog stöder kommandot UNDROP TABLE för att återställa borttagna hanterade tabeller i 7 dagar. Efter 7 dagar markeras den underliggande datan för borttagning från din molnklient under regelbundet tabellunderhåll.

Syntax

DROP TABLE [ IF EXISTS ] table_name [ FORCE ]

Parameter

Exempel

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