Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

DROP TABLE

DROP TABLE

Purpose

Use the DROP TABLE statement to remove a table or an object table and all its data from the database.

Caution: You cannot roll back a DROP TABLE statement.

Note: For an external table, this statement removes only the table metadata in the database. It has no affect on the actual data, which resides outside of the database.

Note: You can perform DDL operations (such as ALTER TABLE, DROP TABLE, CREATE INDEX) on a temporary table only when no session is bound to it. A session becomes bound to a temporary table by performing an INSERT operation on the table. A session becomes unbound to the temporary table by issuing a TRUNCATE statement or at session termination, or, for a transaction-specific temporary table, by issuing a COMMIT or ABORT statement.

Dropping a table invalidates the table’s dependent objects and removes object privileges on the table. If you want to re-create the table, then you must regrant object privileges on the table, re-create the table’s indexes, integrity constraints, and triggers, and respecify its storage parameters. Truncating has none of these effects. Therefore, removing rows with the TRUNCATE statement can be more efficient than dropping and re-creating a table.

17-6 Oracle9i SQL Reference

DROP TABLE

See Also:

CREATE TABLE on page 15-7 for information on creating tables

ALTER TABLE on page 11-2 for information on modifying tables

TRUNCATE on page 18-54 and DELETE on page 16-55 for information on how to remove data from a table without dropping the table

Prerequisites

The table must be in your own schema or you must have the DROP ANY TABLE system privilege.

Syntax

drop_table::=

 

schema

.

CASCADE

CONSTRAINTS

DROP

TABLE

table

 

;

Semantics

schema

Specify the schema containing the table. If you omit schema, then Oracle assumes the table is in your own schema.

table

Specify the name of the table, object table, or index-organized table to be dropped. Oracle automatically performs the following operations:

Removes all rows from the table.

Drops all the table’s indexes and domain indexes, as well as any triggers defined on the table, regardless of who created them or whose schema contains them. If table is partitioned, then any corresponding local index partitions are also dropped.

Drops all the storage tables of table’s nested tables and LOBs.

SQL Statements: DROP SEQUENCE to ROLLBACK 17-7

DROP TABLE

If you drop a range-partitioned or hash-partitioned table, then Oracle drops all the table partitions. If you drop a composite-partitioned table, then all the partitions and subpartitions are also dropped.

For an index-organized table, drops any mapping tables defined on the indexorganized table.

For a domain index, this statement invokes the appropriate drop routines.

See Also: Oracle9i Data Cartridge Developer’s Guide for more information on these routines

If any statistic types are associated with the table, then Oracle disassociates the statistics types with the FORCE clause and removes any user-defined statistics collected with the statistics type.

See Also: ASSOCIATE STATISTICS on page 12-50 and DISASSOCIATE STATISTICS on page 16-64 for more information on statistics type associations

If the table is not part of a cluster, then Oracle returns all data blocks allocated to the table and its indexes to the tablespaces containing the table and its indexes.

Note: To drop a cluster and all its the tables, use the DROP CLUSTER statement with the INCLUDING TABLES clause to avoid dropping each table individually. See DROP CLUSTER on

page 16-67.

If the table is a base table for a view, a container or master table of a materialized view, or if it is referenced in a stored procedure, function, or package, then Oracle invalidates these dependent objects but does not drop them. You cannot use these objects unless you re-create the table or drop and recreate the objects so that they no longer depend on the table.

If you choose to re-create the table, then it must contain all the columns selected by the subqueries originally used to define the materialized views and all the columns referenced in the stored procedures, functions, or packages. Any users previously granted object privileges on the views, stored procedures, functions, or packages need not be regranted these privileges.

17-8 Oracle9i SQL Reference

DROP TABLE

If the table is a master table for a materialized view, then the materialized view can still be queried, but it cannot be refreshed unless the table is re-created so that it contains all the columns selected by the materialized view’s subquery.

If the table has a materialized view log, then Oracle drops this log and any other direct-path INSERT refresh information associated with the table.

Restriction on Dropping Tables You cannot directly drop the storage table of a nested table. Instead, you must drop the nested table column using the ALTER TABLE ... DROP COLUMN clause.

CASCADE CONSTRAINTS

Specify CASCADE CONSTRAINTS to drop all referential integrity constraints that refer to primary and unique keys in the dropped table. If you omit this clause, and such referential integrity constraints exist, then Oracle returns an error and does not drop the table.

Example

Dropping a Table: Example The following statement drops the oe.list_ customers table created in "List Partitioning Example" on page 15-73.

DROP TABLE list_customers;

SQL Statements: DROP SEQUENCE to ROLLBACK 17-9

Соседние файлы в папке Oracle selected docs