Question:
What is the difference between TRUNCATE and DELETE commands?
Answer:
TRUNCATE is a DDL command whereas DELETE is a DML command. Hence DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back.<br>WHERE clause can be used with DELETE and not with TRUNCATE. Source: CoolInterview.com
Truncate resets the identity and delete does not Source: CoolInterview.com
Answered by: swapana | Date:
| Contact swapana
If we use truncate command it will delete the physical structure of the table and retains the logical structure of same as for the next usage.<br>delete is used to delete a particular row from the table. Source: CoolInterview.com
Answered by: jayaprada | Date:
| Contact jayaprada
When we truncate a table then no trigger fired with associate table but in delete sts the trigger will be fire.<br><br>Truncate is fast and delete is not because delete have undo information . Source: CoolInterview.com
Answered by: King saini | Date:
| Contact King saini
Truncate command cant be rollback as its a DDL statement n its much faster then delete as delete command has as undo/rollback segment in which stores the orignal data before delete command so when rollback we get d data as it was before. delete statement can be rollback as its DML statement.for truncate statement we doest hav to commit manually infact after truncate statement there is automatic commit so we cant rollback in truncate whereas in delete we hav to commit manually.one important differenece is that truncate statement frees the storage space where as delete doesnt frees d space. Source: CoolInterview.com
Answered by: sheetal sanghvi | Date:
| Contact sheetal sanghvi
Truncate is a DDL command where as delete is a DML command.<br> The main difference is if we are using truncate command we cant able to rollback the records what we have deleted.But in the case of delete it is possible to rollback the records.<br> The another major difference is delete command deletes the contents of the table row by row,but truncate command will drop the entire table and reconstruct only the structure of the table and this is the reason why truncate is faster than delete.<br><br> Source: CoolInterview.com
Answered by: A.S.Sathish | Date: 2/21/2009
| Contact A.S.Sathish
Truncate is a DDL command where as delete is a DML command.<br> The main difference is if we are using truncate command we cant able to rollback the records what we have deleted.But in the case of delete it is possible to rollback the records.<br> The another major difference is delete command deletes the contents of the table row by row,but truncate command will drop the entire table and reconstruct only the structure of the table and this is the reason why truncate is faster than delete.<br><br> Source: CoolInterview.com
Answered by: hari | Date: 2/23/2009
| Contact hari
By using DELETE DML command we can delete a particular record or all records in a table and can be<br>rollbacked later.In case of TRUNCATE DDL command we can truncate all records in a table and can't be rollbacked later. Source: CoolInterview.com
Answered by: Prabhu.T | Date: 4/19/2009
| Contact Prabhu.T
Sometimes we wish to get rid of all the data in a table. One way of doing this is with DROP TABLE, But what if we wish to simply get rid of the data but not the table itself? For this, we can use the TRUNCATE TABLE command. Source: CoolInterview.com
Answered by: Shankar Gorkhe | Date: 4/19/2009
| Contact Shankar Gorkhe
TRUNCATE is a DDL command whereas is a DML command and DELETE TABLE is a logged operation, so the deletion of each row gets<br>logged in the transaction log, which makes it slow. TRUNCATE TABLE<br>also deletes all the rows in a table, but it won't log the deletion of<br>each row, instead it logs the deallocation of the data pages of the<br>table, which makes it faster. Of course, TRUNCATE TABLE can be rolled<br>back.<br><br> Source: CoolInterview.com
Answered by: Robin Joseph | Date: 8/17/2009
| Contact Robin Joseph
In oracle truncate cant be roll back but in sql server truncate can be rollback.trigger never work for truncate,main concept in HWM(high water mark).<br> Source: CoolInterview.com
Answered by: Shabbir Alam | Date: 8/19/2009
| Contact Shabbir Alam
There is one more difference:<br>Truncate do not return the number of rows deleted.But delete returns the no of rows deleted.<br> Source: CoolInterview.com
Answered by: Yogendra Mishra | Date: 10/31/2009
| Contact Yogendra Mishra
The main difference is if we are using truncate command,we can not use where clause.<br>bt in the case of delete we can use where clause.<br>truncate command will drop the entire table and reconstruct only the structure of the table and this is the reason why truncate is faster than delete. Source: CoolInterview.com
Answered by: sajitha | Date: 11/1/2009
| Contact sajitha
Both Truncate and Delete removes data from table.<br><br>Truncate is a DDL command and cannnot be rolled back.It releases all the memory space after deleting the data.<br><br>Delete is a DML command. We need to perform commit/Rollback to save or undo our changes and Moreover thye memory space is not released after deleting the data.<br><br>Truncate is faster than delete operation.<br> Source: CoolInterview.com
Answered by: kultar kaur | Date: 11/9/2009
| Contact kultar kaur
Truncate is a ddl command where as delete is a dml command. Turncate is faster then delete becuase in turncate no logs are created but in delete logs are created for rollback. Source: CoolInterview.com
Answered by: shukadev sahu | Date: 11/20/2009
| Contact shukadev sahu
TRUNCATE is a DDL command whereas DELETE is a DML command.truncate removes only the content of a object (table,synonym etc)and delete operation deletes all rows and columns by conditionally without modifiying their own structure both are. Source: CoolInterview.com
Answered by: rajesh | Date: 12/8/2009
| Contact rajesh
Truncate is a DDL command where as delete is a DML command.<br> Major difference between delete and truncate is delete command deletes the contents of the table row by row,but truncate command will drop the entire table and reconstruct only the structure of the table and so truncate is faster than delete.<br> If we use truncate command it will delete the physical structure of the table and retains the logical structure of same as for the next usage.<br>delete is used to delete a particular row from the table.<br><br><br><br> Source: CoolInterview.com
Answered by: Nikhil Dudhbaware | Date: 12/15/2009
| Contact Nikhil Dudhbaware
TRUNCATE is a DDL command whereas DELETE is a DML command.Turncate is faster then delete becuase in turncate no logs are created but in delete logs are created for rollback. Source: CoolInterview.com
Answered by: avinash omar | Date: 1/27/2010
| Contact avinash omar
Truncate is DDL command, so it is auto commit.Delete is DML command, we need to do commit after delete transaction. There is concept of "HIGH WATER MARK", truncate resets the high water mark level while delete does not,this is reason truncate is fater than delete. Source: CoolInterview.com
Answered by: vipin kumar | Date: 3/9/2010
| Contact vipin kumar
TRUNCATE is a DDL command whereas DELETE is a DML command.truncate removes only the content of a object (table,synonym etc)and delete operation deletes all rows and columns by conditionally without modifiying their own structure both are. thats all sandeep Source: CoolInterview.com
Answered by: sandeep kumar yadav | Date: 4/15/2010
| Contact sandeep kumar yadav
Truncate command drops the table(delete all the records and drops table) and recreate the table again....delete command delete the records of the table... Source: CoolInterview.com
Answered by: vikram shinde | Date: 4/17/2010
| Contact vikram shinde
In the both the cases data in the table is lost. In delete rowid's and memory of the data is not cleaned. Where as in Truncate rowids and memory also cleaned. Delete can have the rollback facility, because it is DML command. Truncate doesnt have the rollback facility because it is DDL command. Source: CoolInterview.com
Answered by: svphanikumar | Date: 6/10/2010
| Contact svphanikumar
1>TRUNCATE is a DDL command whereas DELETE is a DML command.
2>TRUNCATE is much faster than DELETE.
Reason:When you type DELETE.all the data get copied into the Rollback Tablespace first.then delete operation get performed.Thatswhy when you type ROLLBACK after deleting a table ,you can get back the data(The system get it for you from the Rollback Tablespace).All this process take time.But when you type TRUNCATE,it removes data directly without copying it into the Rollback Tablespace.Thatswhy TRUNCATE is faster.Once you Truncate you cann't get back the data.
3>You cann't rollback in TRUNCATE but in DELETE you can rollback.TRUNCATE removes the record permanently.
4>In case of TRUNCATE ,Trigger doesn't get fired.But in DML commands like DELETE .Trigger get fired.
5>You cann't use conditions(WHERE clause) in TRUNCATE.But in DELETE you can write conditions using WHERE clause Source: CoolInterview.com
Answered by: Dhanabal | Date: 7/4/2010
| Contact Dhanabal
1>TRUNCATE is a DDL command whereas DELETE is a DML command.
2>TRUNCATE is much faster than DELETE.
Reason:When you type DELETE.all the data get copied into the Rollback Tablespace first.then delete operation get performed.Thatswhy when you type ROLLBACK after deleting a table ,you can get back the data(The system get it for you from the Rollback Tablespace).All this process take time.But when you type TRUNCATE,it removes data directly without copying it into the Rollback Tablespace.Thatswhy TRUNCATE is faster.Once you Truncate you cann't get back the data.
3>You cann't rollback in TRUNCATE but in DELETE you can rollback.TRUNCATE removes the record permanently.
4>In case of TRUNCATE ,Trigger doesn't get fired.But in DML commands like DELETE .Trigger get fired.
5>You cann't use conditions(WHERE clause) in TRUNCATE.But in DELETE you can write conditions using WHERE clause Source: CoolInterview.com
Answered by: Dhanabal | Date: 7/4/2010
| Contact Dhanabal
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|