Enterprise Edition Home | Express Edition Home | Previous Page | Next Page   SQL Statements > 4 4 4 4

TRUNCATE (IDS)

4
Use the TRUNCATE statement to quickly delete all rows from a local 4table and free the associated storage space. You can optionally reserve the 4space for the same table and its indexes. Only Dynamic Server supports this implementation 4of the TRUNCATE statement, which is an extension to the ANSI/ISO standard 4for SQL. 4

Extended Parallel Server supports a different implementation of TRUNCATE, as the 4section TRUNCATE (XPS) describes.

4
4

Syntax

4
4
Read syntax diagramSkip visual syntax diagram4             .-TABLE-.
4>>-TRUNCATE--+-------+--+----------+--+-table---+--------------->
4                        '-'owner.'-'  '-synonym-'
4 
4   .-DROP STORAGE--.
4>--+---------------+-------------------------------------------><
4   '-REUSE STORAGE-'
4 
4 4

4 444444444444444444444444444444
Element Description Restrictions Syntax
owner Owner of table or synonym See Usage notes. Owner Name, p. Owner Name
synonym Synonym for the table from which to remove all data Must exist, and USETABLENAME must 4not be set Identifier, p. Identifier
table Name of table from which to remove all data and all B-tree 4structures of its indexes Must exist in the database Identifier, p. Identifier
4
4

Usage

4
4

The TRUNCATE statement rapidly deletes from a local table all active data 4rows and the B-tree structures of indexes on the table. You have the 4option of releasing the storage space that was occupied by the rows and index 4extents, or of reusing the same space when the table is subsequently repopulated 4with new rows.

4

To execute the TRUNCATE statement, you must be the owner of the table, 4or else hold DBA access privilege on the database. You must also hold Delete 4privilege on the table. If an enabled Delete trigger is defined on the table, 4the Alter privilege is also required, even though TRUNCATE does not activate 4triggers.

4

Although it requires the Delete privilege, TRUNCATE is a data definition 4language (DDL) statement. Like other DDL statements, TRUNCATE cannot operate 4on any table outside the database to which you are connected, nor on a table 4that a concurrent session is reading in Dirty Read isolation mode.

4

Dynamic Server always logs the TRUNCATE operation, even for a non-logging 4table. In databases that support transaction logging, only the COMMIT WORK 4or ROLLBACK WORK statement of SQL is valid after the TRUNCATE statement within 4the same transaction.

4

When you rollback a TRUNCATE statement, no rows are removed from the table, 4and the storage extents that hold the rows and index partitions continue to 4be allocated to the table. Only databases with transaction logging can support 4the ROLLBACK WORK statement.

4

After the TRUNCATE statement successfully executes, Dynamic Server automatically 4updates the statistics and distributions for the table and for its indexes 4in the system catalog to show no rows in the table nor in its dbspace partitions. 4It is not necessary to run the UPDATE STATISTICS statement immediately after 4you commit the TRUNCATE statement.

4

If the table that the TRUNCATE statement specifies is a typed table, a 4successful TRUNCATE operation removes all the rows and B-tree structures 4from that table and from all its subtables within the table hierarchy.

4

The TRUNCATE statement does not reset the serial value of SERIAL or SERIAL8 4columns. To reset the counter of a serial column, you must do so explicitly 4by using the MODIFY clause of the ALTER TABLE statement, either before or 4after you execute the TRUNCATE statement.

Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]