TRUNCATE TABLE
Gäller för: Databricks SQL Databricks Runtime
Tar bort alla rader från en tabell eller partition. Tabellen får inte vara en vy eller en extern eller tillfällig tabell. För att trunkera flera partitioner samtidigt anger du partitionerna i partition_spec
. Om ingen partition_spec
har angetts tar du bort alla partitioner i tabellen.
Kommentar
Delta Lake stöder inte partitionssatser för TRUNCATE
.
Om tabellen cachelagras rensar kommandot cachelagrade data i tabellen och alla dess beroenden som refererar till den. Cachen fylls automatiskt när tabellen eller dess beroenden används nästa gång.
Syntax
TRUNCATE TABLE table_name [ PARTITION clause ]
Parametrar
-
Namnet på tabellen som ska avkortas. Namnet får inte innehålla en temporal specifikation eller alternativspecifikation. Om det inte går att hitta tabellen skapar Azure Databricks ett TABLE_OR_VIEW_NOT_FOUND fel.
-
Valfri specifikation av en partition. Stöds inte för Delta Lake.
Exempel
-- Create table Student with partition
> CREATE TABLE Student (name STRING, rollno INT) PARTITIONED BY (age INT);
> SELECT * FROM Student;
name rollno age
---- ------ ---
ABC 1 10
DEF 2 10
XYZ 3 12
-- Remove all rows from the table in the specified partition
> TRUNCATE TABLE Student partition(age=10);
-- After truncate execution, records belonging to partition age=10 are removed
> SELECT * FROM Student;
name rollno age
---- ------ ---
XYZ 3 12
-- Remove all rows from the table from all partitions
> TRUNCATE TABLE Student;
> SELECT * FROM Student;
name rollno age
---- ------ ---