TRUNCATE

TRUNCATE — empties a table

Syntax

TRUNCATE TABLE [schema.]tablename

Description

TRUNCATE TABLE removes all rows from a table. TRUNCATE TABLE may not be rolled back when issued inside a transaction session, prior to issuing a COMMIT. The user must have the DELETE privilege on the table in order to invoke TRUNCATE on it. After execution of TRUNCATE TABLE, disk space is not reclaimed immediately. The NuoDB Check tool (see NuoDB Check) needs to run to reclaim this new unused disk space.

Parameters

Example

Note that inside an explicit transaction, ROLLBACK has no effect when using TRUNCATE TABLE, unlike DELETE, which can be rolled back inside an explicit transaction.

START TRANSACTION;
CREATE TABLE tab_truncate (col1 STRING);
INSERT INTO tab_truncate VALUES ('row1'),('row2'),('row3');
SELECT * FROM tab_truncate;
 COL1  
 ----- 
 row1  
 row2  
 row3  

ROLLBACK;
SELECT * FROM tab_truncate;

/* There are no records selected */