TRUNCATE TABLE
Berlaku untuk: pemeriksaan Databricks SQL 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
-
Nama tabel yang akan dipotok. Nama tidak boleh menyertakan spesifikasi temporal. Jika tabel tidak dapat ditemukan, Azure Databricks menimbulkan kesalahan TABLE_OR_VIEW_NOT_FOUND .
-
Spesifikasi opsional partisi. Tidak didukung untuk Delta Lake.
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
---- ------ ---