GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  SQL Plus
Go To First  |  Previous Question  |  Next Question 
 SQL Plus  |  Question 130 of 132    Print  
How many ways you can delete the table records ?
In how many ways can I delete all the contents of a table and the entire table. Explain with syntax ?


  
Total Answers and Comments: 7 Last Update: September 30, 2009     Asked by: g.ashok1988 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: manipr
 
To delete the records in a table , there are 2 ways .
1.Using the delete statement
2.using the truncate statement .
To delete the entire table drop statement is used .

Deleting a record from a table :
use the following statement.
delete from table_name
where column_name = some_value; .
The above statement deletes a single record at a time.

To delete all the records in a table the following statement is used.
delete * from table_name;

coming to the truncate statement , its like a delete statement without a where clause. the syntax is
Truncate table table_name.
It also removes all the records in the table.
In case of delete * from table_name and truncate table table_name all the records in the table is deleted but the table structure and its columns , constraints , indexes remain the same .

To remove the table from the database,use the drop table statement.
drop table table_name;



Above answer was rated as good by the following members:
anjaliraj, badhan, Riaz Ahmed, xceptionalsiva
July 17, 2008 11:20:29   #1  
manipr Member Since: June 2008   Contribution: 1    

RE: How many ways you can delete the table records ?
To delete the records in a table there are 2 ways .
1.Using the delete statement
2.using the truncate statement .
To delete the entire table drop statement is used .

Deleting a record from a table :
use the following statement.
delete from table_name
where column_name some_value; .
The above statement deletes a single record at a time.

To delete all the records in a table the following statement is used.
delete * from table_name;

coming to the truncate statement its like a delete statement without a where clause. the syntax is
Truncate table table_name.
It also removes all the records in the table.
In case of delete * from table_name and truncate table table_name all the records in the table is deleted but the table structure and its columns constraints indexes remain the same .

To remove the table from the database use the drop table statement.
drop table table_name;


 
Is this answer useful? Yes | NoAnswer is useful 3   Answer is not useful 0Overall Rating: +3    
December 19, 2008 00:35:17   #2  
praveen_appu47 Member Since: December 2008   Contribution: 1    

RE: How many ways you can delete the table records ?
There are two ways To delete all records in the table.
1. using delete
2. using truncate
In delete option we have used drop command. eg. drop table table_name;
for second one eg. truncate tablename; Both are delete the records in a table.

 
Is this answer useful? Yes | No
April 25, 2009 04:30:29   #3  
jeetuparida Member Since: April 2009   Contribution: 11    

RE: How many ways you can delete the table records ?
There are two way to delete table record.
If you want to delete specify record to use delete command delete table table_name

but do you want to delete all the table record to use truncate table_name.

 
Is this answer useful? Yes | No
May 20, 2009 04:22:02   #4  
priyaraja2k2 Member Since: May 2009   Contribution: 1    

RE: How many ways you can delete the table records ?

We have 2 options :


1. Delete

2.Truncate


Delete : It is DML concepts.

Syntax: Delete from <table_name>;

Example: Delete from emp;

Explain: The above query will delete all the record from the tale. Supose need
to delete the particular record from the table we can give the condition.


Syntax: Delete from <table_name> where <condition>

Example: Delete from emp where emp_no 101;

Explain: By default You gave the condition 101 instead of 1001. You can Rollback
and get the 101 record before doing commit.


Truncate : It is DDL commend.

Syntax: Truncate Table <Table_Name>;

Example: Truncate Table Emp;

Explain: The above query will delete all the record from the table. Suppose need
to delete the particular record from the table we cannot give the condition.

Once we truncate the table we cannot Rollback.


DROP : Remove the table from data base.

Syntax: Drop Table <Table_Name>

Example : Drop Table Emp;


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
May 20, 2009 07:05:47   #5  
Arpit Gautam Member Since: May 2009   Contribution: 1    

RE: How many ways you can delete the table records ?
If you want to delete only few rows from Table then use

Delete Table <Tablename>
where <condiition>


It will just delete the data but not unhold the space.



If you want to remove whole data then
Truncate table <Tablename>

will remove all rows and unhold the space.

Delete Table <Tablename> will also do that but it won't unhold the space.

 
Is this answer useful? Yes | No
June 24, 2009 00:29:59   #6  
Shivani Goel Member Since: June 2009   Contribution: 5    

RE: How many ways you can delete the table records ?

Two ways
1. DELETE
2. TRANCATE


BY using delete----
U can delete one nd all rows by using delete command
syntax-
delete from tablename where column_name column_value;
(it will delete the row related to given column value)
delete * from tablename;
(it will remove all the rows from the table)
NOTE-1- In case of delete stil high water mark remain set to same position even
after deleteing all the rows.
2- Also the rows never release the memory space .
3- U can rollback in case of delete.



BY using trancate-----
U can delete all the rows by using the trancate command.
syntax-
trancate table tablename;

NOTE- 1- in case of trancate high water mark get set to zero.
2- all the rows get deleted nd relase the memory space but structure
index nd constraint remain the same.
3- U can never rollback in case of trancate command.


 
Is this answer useful? Yes | No
September 30, 2009 01:00:59   #7  
surya72446 Member Since: September 2009   Contribution: 2    

How many ways you can delete the table records ?
Actually there are three ways to delete a table

1. Delete: This is used to delete the one or all the records. The thing with this is that only data is been deleted but the table structure and the memory allocated to it is safe.

2. Truncate: Truncate is similar to Delete the only difference is that it keeps the structure but removes the memory allocated to the table.

3. Drop: This is used to delete the entire table along with the table structure and memory allocated to it.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape