TABEL TRUNCATE

Van toepassing op:gemarkeerd met ja Databricks SQL-controle gemarkeerd als ja Databricks Runtime

Hiermee verwijdert u alle rijen uit een tabel of partitie(s). De tabel mag geen weergave of een externe of tijdelijke tabel zijn. Als u meerdere partities tegelijk wilt afkappen, geeft u de partities op in partition_spec. Als er geen partition_spec is opgegeven, verwijdert u alle partities in de tabel.

Opmerking

Delta Lake biedt geen ondersteuning voor partitieclausules voor TRUNCATE.

Als de tabel in de cache is opgeslagen, worden met de opdracht gegevens in de cache gewist van de tabel en alle afhankelijke items die ernaar verwijzen. De cache wordt langzaam gevuld wanneer de volgende keer de tabel of de afhankelijke items worden geopend.

Syntaxis

TRUNCATE TABLE table_name [ PARTITION clause ]

Parameters

Voorbeelden

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