TRUNCATE TABLE

更新时间:
复制 MD 格式

Removes all rows from a table while preserving its schema and indexes.

Applicable engines

LindormTable

Syntax

TRUNCATE TABLE table_identifier

Usage notes

  • SQL engine 2.6.10 or later: Run TRUNCATE TABLE directly.

  • SQL engine earlier than 2.6.10: Set the table to OFFLINE status using OFFLINE TABLE before running TRUNCATE TABLE.

TRUNCATE TABLE removes all row data but does not delete the table schema or indexes.

Examples

The following examples clear all data from the sensor table.

SQL engine 2.6.10 or later

TRUNCATE TABLE sensor;

SQL engine earlier than 2.6.10

-- Set the table to OFFLINE first.
OFFLINE TABLE sensor;

-- Clear all data from the table.
TRUNCATE TABLE sensor;