Data Warehousing Community Forum
February 09, 2012, 12:54:31 pm

Pages: [1]   Go Down
  Print  
Author Topic: Difference between Truncate and Delete?  (Read 1432 times)
Sipra
Founder
*****

Reputation: +59/-0
Offline Offline

Posts: 323


Am the King...


View Profile WWW
« on: June 19, 2007, 02:59:02 pm »

Hi all.

Almost all the beginners/experts will atleast confuse a little bit while answering this question.
Similarly I had it a long time back.

Truncate is a DDL command and Delete is a DML command.

After execution of DDL statements commit performs implicitly. That is why your changes are committed automatically when ever you perform a DDL statement ( Create,Alter,Drop,Truncate,rename, etc).

DML statements does not commit your changes. You have to commit explicitly inorder to save your changes. Examples of DML commands are select, insert, update, Delete etc.

Simply to say - DML statements can be rollbacked where DDL are autocommit.

Please share if you have any inputs also....
Logged

Whoever
Administrator
*****

Reputation: +34/-0
Offline Offline

Posts: 124



View Profile WWW
« Reply #1 on: July 17, 2007, 03:10:17 pm »

DELETE is used to remove specific rows (or all the rows from a table) by using Where clause, however TRUNCATE is used to remove all the rows from the table in which we can't use this.

Logged

If most people said what’s on their minds, they’d be speechless.
Raj2007
DW Apprentice
**

Reputation: +3/-0
Offline Offline

Posts: 25


Lightning for DW Forum


View Profile
« Reply #2 on: July 24, 2007, 01:51:40 pm »

TRUNCATE is faster as it is a DDL statement and no rollback segment needed.
And data cannot be retrieved in normal conditions since DDL has no explicit commit is required.

DELETE is a bit slower as it is a DML Statement and rollback segment is required.
Selective data can be deleted using where condition and commit needs to be done to complete the transaction.
Logged
unknown
DW Apprentice
**

Reputation: +8/-0
Offline Offline

Posts: 44



View Profile
« Reply #3 on: January 19, 2008, 11:40:18 pm »

TRUNCATE is faster
DELETE is a bit slower

Why Truncate is faster than Delete ?
Logged

Thanks
Unknown Smiley
Sipra
Founder
*****

Reputation: +59/-0
Offline Offline

Posts: 323


Am the King...


View Profile WWW
« Reply #4 on: January 21, 2008, 11:02:54 am »

Deleting a table is logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow.

Truncate table also deletes all the rows in a table, but it won’t log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster.

And we need to remember all the time, that Truncat[e]'ing a table can't be rolled back.
Logged

samishta
DW Fresher
*

Reputation: +2/-0
Offline Offline

Posts: 17



View Profile
« Reply #5 on: May 29, 2008, 12:32:52 am »

Delete command deletes the rows one by one. The records are logged. You can easily rollback on the delete statement. While the truncate simply truncates the whole of table and releases space. Thus truncate i believe is more efficient.

Delete is usually used when we ought to be selective about the records we delete.
Logged
Arvind
DW Apprentice
**

Reputation: +10/-0
Offline Offline

Posts: 78


View Profile
« Reply #6 on: June 22, 2011, 11:41:53 am »

There is one more difference between these two -

TRUNCATE command resets the High Water Mark for the table but DELETE does not.
So TRUNCATE operations on table are much faster.
Logged

regards,
Arvind
Pages: [1]   Go Up
  Print  
 
Jump to: