GeekInterview.com
Series: Subject: Topic:
Question: 68 of 133

What is difference between TRUNCATE & DELETE ?

TRUNCATE commits after deleting entire table i.e., can not be rolled back. Database triggers do not fire on TRUNCATEDELETE allows the filtered deletion. Deleted records can be rolled back or committed.Database triggers fire on DELETE.
Asked by: Interview Candidate | Asked on: Sep 7th, 2004
Showing Answers 1 - 9 of 9 Answers
rajaramian

Answered On : Feb 8th, 2006

We can ROLLBACK the DELETE statement but we can not ROLLBACK the TRUNCATE statement

  
Login to rate this answer.

Delete generates rollback segments, and its DML

Truncate does not generate rollback segment and its DDL

once Truncate does not generate rollback so its faster then delete

  
Login to rate this answer.
prince maruthi

Answered On : Feb 9th, 2007

truncate=DELETE+COMMIT;

delete=delete+rollback;we can rollback after the delete command ,then we can get the deleted data

  
Login to rate this answer.
riteshratna

Answered On : May 11th, 2007

View all answers by riteshratna

Delete
Delete remove the Data only, the Table structure remains intact.

This is a DML Statement
Rollback possible
No Commit is performed neither before nor after. (Because it is a DML Statement).
They take locks on rows,
They generate redo (lots of it)
They require segments in the UNDO tablespace.
A delete does not relinquish segment space thus a table in which all records have been deleted retains all of its original blocks.
A truncate does not move the High Water Mark of the table back to zero, it retains its original position.
Delete deletes the specific rows filtered by where statement. and log is maintained for it.
It can activate the triggers.

Truncate
Truncate remove the Data only, the Table structure remains intact.
This is a DDL Statement
Rollback not possible (Except in SQL 2005)
It issues a COMMIT before it acts and another COMMIT afterward so no rollback of the transaction is possible. (Because it is a DDL Statement)
No row-level locks are taken.
No redo or rollback is generated.
They do not require segments in the UNDO tablespace.
All extents bar the initial are de-allocated from the table
A truncate moves the High Water Mark of the table back to zero
Truncate deletes the page associated with the table so all indexes are reset
It does not activate the triggers.

  
Login to rate this answer.
sheel

Answered On : May 17th, 2007

Hi friends
In truncate command deletion of row happen but one important thing is that, after truncate memory space is also empty or you can say that operation going on memoryelement is deleted from memory permanetly. that is why they cannot rollback.
But in case of delete commandthe element is still present in memoryso memory is not empty after the delete operationso they can rollback after deletion. thanx

if any one has new logic plz send me

  
Login to rate this answer.

1) Rollback : Not possible in Truncate but possible in Delete because it
Delete uses the rollback Segments.

2) Trigger : If we have a Delete Trigger, it will not be fired in case of
Truncate.

3) Type : Delete is a DML Type of statement but Truncate is a DDL statement.

4) Speed : Truncate is much faster than Delete because it does not use the
rollback segments

5) High Water Mark : The High water mark of the table is set to 0 in case of
Truncate but this variable retains its original value in Delete.

  
Login to rate this answer.

1. Truncate is a DDL command where as Delete  is DML.
2. There is no rollback for Truncate where as for Delete we can rollback.

  
Login to rate this answer.
nandk.sharma

Answered On : Jun 27th, 2008

View all answers by nandk.sharma

TRUNCATE -  Truncate is a ddl command.

DELETE-     Delete is a dml command.

TRUNCATE - We can not use 'where' clause with truncate.

DELETE-      We can use 'where '  clause  with delete .

  
Login to rate this answer.
nandk.sharma

Answered On : Jun 27th, 2008

View all answers by nandk.sharma

Truncate is faster than delete as it does not generate rollback segment.

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Ads

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.