What is the difference between TRUNCATE and DELETE?
James Tomar
DELETE 1. DELETE is a DML Command. 2. DELETE statement is executed using a row lock, each row in the table is locked for deletion. 3. We can specify filters in where clause 4. It deletes specified data if where condition exists. 5. Delete activates a trigger because the operation are logged individually. 6. Slower than truncate because, it keeps logs. 7. Rollback is possible.TRUNCATE 1. TRUNCATE is a DDL command. 2. TRUNCATE TABLE always locks the table and page but not each row. 3. Cannot use Where Condition. 4. It Removes all the data. 5. TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. 6. Faster in performance wise, because it doesn't keep any logs. 7. Rollback is not possible.
delete basically delete all rows but PK(id) will start from that location eg if we insert 10 records and then delete that then id will start from 11 while if we use truncate all rows will be deleted and id will reset(start from 1)
truncate use removing all records from tables. you can not use where clause in case of truncate but with delete , you can delete particular record from the tables.
DELETE :1. This statement delete one or more rows based on condition 2. We can get back the rows using ROLLBACK statement TRUNCATE: 1. This Statement delete all the rows. 2. We cannot get back the deleted rows using ROLLBACK statement
DELETE 1. DELETE is a DML Command. 2. DELETE statement is executed using a row lock, each row in the table is locked for deletion. 3. We can specify filters in where clause 4. It deletes specified data if where condition exists. 5. Delete activates a trigger because the operation are logged individually. 6. Slower than truncate because, it keeps logs. 7. Rollback is possible. TRUNCATE 1. TRUNCATE is a DDL command. 2. TRUNCATE TABLE always locks the table and page but not each row. 3. Cannot use Where Condition. 4. It Removes all the data. 5. TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions. 6. Faster in performance wise, because it doesn't keep any logs. 7. Rollback is not possible.For more difference http://dotnet-munesh.blogspot.in/2013/12/difference.html
DELETE Statement: This command deletes only the rows from the table based on the condition given in the where clause or deletes all the rows from the table if no condition is specified. But it does not free the space containing the table.TRUNCATE statement: This command is used to delete all the rows from the table and free the space containing the table.
truncate command delete all records from the table and using delete command delete one record or more records,