Oracle8i SQL Reference Release 3 (8.1.7) Part Number A85397-01 |
|
SQL Statements:
DROP SEQUENCE to UPDATE, 26 of 27
Use the TRUNCATE
statement to remove all rows from a table or cluster and reset the STORAGE
parameters to the values when the table or cluster was created.
Deleting rows with the TRUNCATE
statement can be more efficient than dropping and re-creating a table. Dropping and re-creating a table invalidates the table's dependent objects, requires you to regrant object privileges on the table, and requires you to re-create the table's indexes, integrity constraint, and triggers and respecify its storage parameters. Truncating has none of these effects.
To truncate a table or cluster, the table or cluster must be in your schema or you must have DROP
ANY
TABLE
system privilege.
TABLE
Specify the schema and name of the table to be truncated. This table cannot be part of a cluster. If you omit schema
, Oracle assumes the table is in your own cluster.
NEXT
is changed to be the size of the last extent deleted from the segment in the process of truncation.
UNUSABLE
indicators for the following indexes on table
: range and hash partitions of local indexes and subpartitions of local indexes.
table
is not empty, Oracle marks UNUSABLE
all nonpartitioned indexes and all partitions of global partitioned indexes on the table.
table
(whether it is a regular or index-organized table) contains LOB columns, all LOB data and LOB index segments will be truncated.
table
is partitioned, all partitions or subpartitions, as well as the LOB data and LOB index segments for each partition or subpartition, will be truncated.
Restrictions:
LOADING
or FAILED
.
SNAPSHOT
LOG
The SNAPSHOT
LOG
clause lets you specify whether a snapshot log defined on the table is to be preserved or purged when the table is truncated. This clause allows snapshot master tables to be reorganized through export/import without affecting the ability of primary-key snapshots defined on the master to be fast refreshed. To support continued fast refresh of primary-key snapshots, the snapshot log must record primary-key information.
CLUSTER
Specify the schema and name of the cluster to be truncated. You can truncate only an indexed cluster, not a hash cluster. If you omit schema
, Oracle assumes the table is in your own cluster.
When you truncate a cluster, Oracle also automatically deletes all data in the cluster's tables' indexes.
STORAGE
Clauses
The DROP
STORAGE
clause and REUSE
STORAGE
clause also apply to the space freed by the data deleted from associated indexes.
TRUNCATE
Example
The following statement deletes all rows from the emp
table and returns the freed space to the tablespace containing emp
:
TRUNCATE TABLE emp;
The above statement also deletes all data from all indexes on emp
and returns the freed space to the tablespaces containing them.
The following statement deletes all rows from all tables in the cust
cluster, but leaves the freed space allocated to the tables:
TRUNCATE CLUSTER cust REUSE STORAGE
The above statement also deletes all data from all indexes on the tables in cust
.
The following statements are examples of truncate statements that preserve snapshot logs:
TRUNCATE TABLE emp PRESERVE SNAPSHOT LOG; TRUNCATE TABLE stock;
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|