|
 |
|
Oracle DROP TABLE Tips
Oracle Tips by Burleson Consulting |
DROP TABLE Tips
The DROP TABLE command allows you to drop tables from
your Oracle database. In this example we drop the BOOKS table that we created
earlier in this chapter
DROP TABLE books;
Oracle 10g has a recycle bin, kind of a
retirement home for old and dropped tables. You can recover a table that you have dropped from the recycle
bin using the flashback table command as seen here:
SQL> DROP TABLE books;
SQL> FLASHBACK TABLE
books TO BEFORE DROP;
Dropped a table by accident? In Oracle Database 10g the
flashback table command will recover the dropped table and many of the objects
associated with the dropped table. When you drop a table, some things are not recovered like bitmap join
indexes (and advanced kind of index we will not cover in this book) and
foreign key constraints (which we do cover in this book).
When dealing with a table that has been dropped, the flashback table command works most of the time,
though the longer ago the table was dropped, the less likely it will be in the
recycle bin. The recycle bin where dropped tables go is purged by Oracle from time to time based on a number
of different criteria. You can see the contents of the recycle bin, including
any table that you have dropped, from
SQL*Plus by using the show recyclebin command:
SQL> show
recyclebin;
ORIGINAL
NAME RECYCLEBIN NAME OBJECT TYPE DROP TIME ---------------- ------------------------------ ------------ ------------ BOOKS BIN$D3XWKKUCQVq2EG8/vkjNDw==$0 TABLE 2005-05-30
To completely remove a table from the tablespace, we use the DROP TABLE
command.
This command’s format follows:
DROP TABLE [schema.]table_name [CASCADE CONSTRAINTS]
Remember, Oracle will drop the table regardless of its contents and the drop
table command will still execute, even if the table contains a zillion rows.
The only time a drop table command will fail is when a table’s primary key
is referenced by another table’s foreign key via a restraint clause.
To find all references the point to a specific table,
see these notes on
finding all references to a table.
This is an excerpt from the bestselling "Easy
Oracle Jumpstart" by Robert Freeman and Steve Karam (Oracle ACE and Oracle
Certified Master). It’s only $19.95 when you buy it directly from the
publisher
here.
 |
If you like Oracle tuning, you may enjoy the new book "Oracle
Tuning: The Definitive Reference", over 900 pages of BC's favorite tuning
tips & scripts.
You can buy it direct from the publisher for 30%-off and get instant access to
the code depot of Oracle tuning scripts. |
|