Oracle8i SQL Reference Release 2 (8.1.6) A76989-01 |
|
SQL Statements (continued), 4 of 5
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.
The table or cluster must be in your schema or you must have DROP
ANY
TABLE
system privilege.
|
specifies 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. |
|
|
You can truncate index-organized tables and temporary tables. When you truncate a temporary table, only the rows created during the current session are truncated. |
|
|
The table's storage parameter |
|
|
Oracle also automatically truncates and resets any existing
If table is not empty, Oracle marks |
|
|
For a domain index, this statement invokes the appropriate truncate routine to truncate the domain index data. |
|
|
If table (whether it is a regular or index-organized table) contains
If table is partitioned, all partitions or subpartitions, as well as the |
|
|
Note: When you truncate a table, Oracle automatically deletes all data in the table's indexes and any materialized view direct-load |
|
|
Restrictions:
|
|
|
specifies 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.
See Also: Oracle8i Replication for more information about snapshot logs and the |
|
|
|
specifies that any snapshot log should be preserved when the master table is truncated. This is the default. |
|
|
specifies that any snapshot log should be purged when the master table is truncated. |
|
specifies 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. |
|
|
deallocates all space from the deleted rows from the table or cluster except the space allocated by the table's or cluster's |
|
|
retains the space from the deleted rows allocated to the table or cluster. Storage values are not reset to the values when the table or cluster was created. This space can subsequently be used only by new data in the table or cluster resulting from inserts or updates. |
|
|
The |
|
|
Note: If you have specified more than one free list for the object you are truncating, the |
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 © 1999 Oracle Corporation. All Rights Reserved. |
|