TRUNCATE TABLE

Berlaku untuk:check ditandai ya pemeriksaan Databricks SQL ditandai ya Databricks Runtime

Menghapus semua baris dari tabel atau partisi. Tabel tidak boleh berupa tampilan atau tabel eksternal atau sementara. Untuk memotong beberapa partisi sekaligus, tentukan partisi di partition_spec. Jika tidak partition_spec ditentukan, menghapus semua partisi dalam tabel.

Catatan

Delta Lake tidak mendukung klausul partisi untuk TRUNCATE.

Jika tabel di-cache, perintah menghapus data tabel yang di-cache dan semua dependennya yang merujuknya. Cache akan diisi dengan malas ketika tabel atau dependen diakses lain kali.

Sintaks

TRUNCATE TABLE table_name [ PARTITION clause ]

Parameter

Contoh

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