TRUNCATE | DELETE |
---|---|
TRUNCATE is a DDL command | DELETE is a DML command |
TRUNCATE is executed using a table lock and whole table is locked for remove all records. | DELETE is executed using a row lock, each row in the table is locked for deletion. |
We cannot use Where clause with TRUNCATE. | We can use where clause with DELETE to filter & delete specific records. |
Minimal logging in transaction log, so it is performance wise faster. | It maintain the log, so it slower than TRUNCATE. |
TRUNCATE TABLE removes the data by deallocating the data pages used to store the table data and records only the page deallocations in the transaction log. | The DELETE statement removes rows one at a time and records an entry in the transaction log for each deleted row |
Identify column is reset to its seed value if table contains any identity column. | Identity of column keep DELETE retain the identity |
To use Truncate on a table you need at least ALTER permission on the table. | To use Delete you need DELETE permission on the table. |
Truncate uses the less transaction space than Delete statement. | Delete uses the more transaction space than Truncate statement. |
Truncate cannot be used with indexed views | Delete can be used with indexed views |
TRUNCATE TABLE can’t activate a trigger because the operation does not log individual row deletions. When we run truncate command to remove all rows of table then it actually doesn’t removes any row, rather it deallocates the data pages. In case of Truncate triggers will not be fired because no modification takes place, we have just deallocated the data pages not deleted any row from table. | Delete activates a trigger because the operation are logged individually. When we execute Delete command, DELETE trigger will be initiated if present. Delete is a DML command and it deletes the data on row-by-row basis from a table. Which means delete is modifying the data by deleting it from the table. Triggers are fired when a DML statement executed on a table, so trigger will be fired in case of Delete command execution. |
Sunday, February 1, 2015
Difference between Truncate and Delete Command in SQL
Subscribe to:
Post Comments (Atom)
Popular Posts
-
Problem Statement - While creating Power Automate we may face situation where connection reference for the Dataverse Connector missing and w...
-
Many times, it happens that we get an error or exception message while working on the Dynamics 365 UCI form . So, to get more informatio...
-
Objective - To Create Guid PCF Control Pre-Requisites Install Node Js - https://nodejs.org/en/ Install Power Apps CLI - http://download.mi...
-
1. Clone Repository – Login to Azure Devops, open Project, go to Repos and click on “Clone” Note – Here we are using the reposi...
-
Microsoft is about to bring low code power for Model-driven Power Apps and Dataverse using Power Fx. Some areas of innovation: Model-driven ...
No comments:
Post a Comment