Wednesday, 13 April 2016

Drop

Drop:

Dropping the table means deleting the data of the table along with its definition(structure of the table).

The difference between the truncate and drop:
 Truncate : only deleting the content or  entire records  of the data.
  Drop : deleting the entire table along with its content or records.


 lets create a table:
 create table student(sid number primary key,firstname varchar2(50) not null,lastname varchar2(50) not null,email varchar2(50) not null unique);

now lets drop the table:
 drop table student;

the log will be:
drop table student succeeded.

now just see the description of the table by following query:

desc student;

the log will be:
ERROR: object STUDENT does not exist

now if we want to get the table back. fire the following query:

flashback table student to before drop;

the log will be:
flashback table succeeded.

now again see the description of the log:
Name                           Null     Type                                                                                                                                                                                        
------------------------------ -------- ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
SID                            NOT NULL NUMBER                                                                                                                                                                                      
FIRSTNAME                      NOT NULL VARCHAR2(50)                                                                                                                                                                                
LASTNAME                       NOT NULL VARCHAR2(50)                                                                                                                                                                                
EMAIL                          NOT NULL VARCHAR2(50)


Flashback:

when the table is dropped along with its records , if we use flashback then the table along with the data is restored. but the triggers which are created on the table does not work. you have to create the trigger again.

we can use rename to with the flashback;

Example: flashback table student to before drop rename to student_new;

Conclusion:
 whenever a table is dropped the associated triggers are also dropped.




No comments:

Post a Comment