Partilhar via


TRUNCATE TABLE

Aplica-se a:Marque Sim Databricks SQL Marque Sim Databricks Runtime

Remova todas as linhas de um table ou partition. O table não deve ser uma vista ou uma tableexterna ou temporária. Para truncar várias partições de uma só vez, especifique as partições em partition_spec. Se nenhum partition_spec for especificado, remove todas as partições no table.

Nota

Delta Lake não suporta cláusulas partition para TRUNCATE.

Se o table estiver armazenado em cache, o comando limpará os dados armazenados em cache do table e de todos os seus dependentes que se referem a ele. O cache será preenchido de forma preguiçosa da próxima vez que o table ou os dependentes forem acessados.

Sintaxe

TRUNCATE TABLE table_name [ PARTITION clause ]

Parameters

Exemplos

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