TRUNKERA TABELL

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

Tar bort alla rader från en tabell eller partitioner. 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 nej partition_spec anges tar du bort alla partitioner i tabellen.

Observera

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 lazily när tabellen eller de beroende används nästa gång.

Syntax

TRUNCATE TABLE table_name [ PARTITION clause ]

Parametrar

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