TRUNCATE TABLE

Si applica a:check contrassegnato sì controllo SQL databricks contrassegnato come sì Databricks Runtime

Rimuove tutte le righe da una tabella o da una partizione. La tabella non deve essere una vista o una tabella esterna o temporanea. Per troncare più partizioni contemporaneamente, specificare le partizioni in partition_spec. Se non partition_spec viene specificato alcun valore, rimuove tutte le partizioni nella tabella.

Nota

Delta Lake non supporta le clausole di partizione per TRUNCATE.

Se la tabella viene memorizzata nella cache, il comando cancella i dati memorizzati nella cache della tabella e tutti i relativi dipendenti che lo fanno riferimento. La cache verrà riempita in modo più pigro quando la tabella o i dipendenti vengono accessibili alla successiva volta.

Sintassi

TRUNCATE TABLE table_name [ PARTITION clause ]

Parametri

Esempi

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