All Products
Search
Document Center

TRUNCATE TABLE

Last Updated: Jun 18, 2021

Description

The TRUNCATE TABLE statement fully clears a specified table but retains the table schema that includes the defined partition information in the table. This statement is logically the same as the DELETE FROM statement that deletes all rows. To execute the TRUNCATE statement, you must have the permissions to delete and create tables.

The TRUNCATE TABLE and DELETE FROM statements have the following differences:

  • The TRUNCATE TABLE operation cancels and recreates the table. This is much faster than deleting rows one after one.

  • The result of the TRUNCATE TABLE statement shows that the number of affected rows is always 0.

Syntax

TRUNCATE [TABLE] table_name;

Parameter description

Parameter

Description

table_name

Specifies the table name.

Examples

  • Fully clears table tb1.

OceanBase(root@oceanbase)>TRUNCATE TABLE tb1;