Difference Between Drop And Drop Purge In Oracle
Asked Answered
B

8

29

I am using Oracle Database and I am a bit confused about Drop and Purge Commands. In fact for me both does the same thing. Removes the table with schema from database. What is the main difference between these two?

  1. Drop Table Tablename;
  2. Drop Table Tablename Purge;
Bickford answered 10/10, 2011 at 13:24 Comment(2)
Isn't this a Read the manual question? And how can it be both MySQL and Oracle?Beefwood
@Dems "Read the manual" ... as are most Oracle questions on Stackoverflow, sadly.Uncommon
S
51

Normally, a table is moved into the recycle bin (as of Oracle 10g), if it is dropped. However, if the purge modifier is specified as well, the table is unrecoverably (entirely) dropped from the database.

Shutter answered 10/10, 2011 at 13:28 Comment(2)
+1 I would add that if you don't add purge the table will continue to use space in the recycle bin so if you're cleaning up it's better to use it.Twinflower
Id agree with Ben about space usage, use purge, or I've seen a truncate table followed by a drop to have similar effect.Stet
S
7

Oracle Database 10g introduces a new feature for dropping tables. When you drop a table, the database does not immediately release the space associated with the table. Rather, the database renames the table and places it in a recycle bin, where it can later be recovered with the FLASHBACK TABLE statement if you find that you dropped the table in error. If you want to immediately release the space associated with the table at the time you issue the DROP TABLE statement, then include the PURGE clause as follows. DROP TABLE employees PURGE; Specify PURGE only if you want to drop the table and release the space associated with it in a single step. If you specify PURGE, then the database does not place the table and its dependent objects into the recycle bin. NOTE: You cannot roll back a DROP TABLE statement with the PURGE clause, and you cannot recover the table if you drop it with the PURGE clause. This feature was not available in earlier releases.

Singapore answered 29/8, 2013 at 5:23 Comment(0)
P
4

A link to asktom article: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:32543538041420

Basically with oracle10, all dropped tables go into recycle bin from where they can be undropped. With purge you basically skip the recycle bin part and you drop the table without an option to undo the action.

Passably answered 10/10, 2011 at 13:29 Comment(0)
V
1
SQL>drop table table_name;

This command deletes the table named table_name, but internally it is moved to recycle bin of oracle (which is just similar to deleting any file/folder using Delete key on windows os).
Benefits:
1. We will be able to restore the above deleted table if required.
Drawbacks:
1. Still occupies some amount of memory.

SQL>drop table table_name purge;

This command deletes the table table_name completely from the database (which is similar to deleting any file/folder using Shift + Delete key on windows OS).

The Benefits and Drawbacks will be vice-verse of the above.

Variegated answered 26/2, 2014 at 18:55 Comment(0)
M
1

The below statement will drop the table and place it into the recycle bin.

DROP TABLE emp_new;

The below statement will drop the table and flush it out from the recycle bin also.

DROP TABLE emp_new PURGE;

Middlebrow answered 3/12, 2014 at 4:58 Comment(1)
Why has it been voted down? Some comment would have helped? To me it looks correct..Moldavia
T
1

It’s clear from @Randy comment, just to add on:

(1) Drop Table Tablename:

Without purge, the table can be in the RECYCLEBIN or USER_RECYCLEBIN; which can be restored using the command FLASHBACK. This is similar to files we delete in our windows desktop, which move to the recycle bin, and can be restored back.

(2) Drop Table Tablename Purge:

If Drop is given along with Purge, its tablespace is released and cannot be restored. (Like Shift+Delete in desktop)

Following example gives practical example:

create table test_client (val_cli integer, status varchar2(10));
drop table test_client ;

select tablespace_name from all_tables where owner = 'test' and table_name = 'TEST_CLIENT';

SELECT * FROM RECYCLEBIN where ORIGINAL_NAME='TEST_CLIENT';

SELECT * FROM USER_RECYCLEBIN where ORIGINAL_NAME='TEST_CLIENT';

FLASHBACK TABLE test_client  TO BEFORE DROP;

select tablespace_name from all_tables where owner = 'test' and table_name = 'TEST_CLIENT';

drop table test_client purge;

select tablespace_name from all_tables where owner = 'test' and table_name = 'TEST_CLIENT';
Tailorbird answered 10/7, 2019 at 23:7 Comment(0)
S
0

If you don't use the recycle bin, or know that it exists, an alternative to using the PURGE option is to turn of the recycle bin for the session that is dropping tables.

ALTER SESSION SET RECYCLEBIN = OFF;

Selfregulating answered 24/4 at 16:54 Comment(0)
A
-1

drop table table_name purge;

By using this query what happened:- Normally, a table is moved into the recycle bin (as of Oracle 10g), if it is dropped.But still occupied the memory in database so to release the the memory for another object we can use the the Purge clause.

Albaalbacete answered 20/2, 2014 at 13:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.