Skip to main content

Delete Vs Truncate


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. Delete activates a trigger because the operation are logged individually. 
5. Slower than truncate because, it keeps logs. 
6. Rollback is possible.


7. We can use Delete command in all types of replications

Delete From [schama].[table_name]

Truncate 


1. TRUNCATE is a DDL command. 
2. TRUNCATE TABLE always locks the table and page but not each row. 
3. We cannot use where Condition in Truncate. 
4. It Deletes all the table's data. 
5. TRUNCATE Table cannot activate a trigger.
6.  Faster in performance wise, because it doesn't keep any logs. 
7.  Rollback is also possible. 

8.  It reset all the constraints i.e. IDENTITY.
9.  T-Replication/Merge-Replication not supports TRUNCATE TABLE COMMAND if the Table is published.
10. We can not truncate a table that has a foreign key reference.
11. We can not truncate a table that participates in an indexed view.
12. For Truncate a Table the minimum permission required is ALTER on the table.

Truncate Table [schama].[table_name]
 

Comments

Post a Comment

Popular posts from this blog

SQL Browser Service

SQL Browser Service SQL browser service runs as a Windows Services on the windows machine. Start and Stop SQL Browser Services It's possible using SSCM or Windows services.. From SSCM From Windows Services Use of SQL Browser Services: It listin all the incoming request which come for server resources and provide information about SQL instances that are installed on the machine. Below are the task of SQL browser:   1. Browsing the available SQL Servers.   2. Connect to the correct SQL instance.   3. Connect to DAC (Dedicated Admin Connection) . By Abhishek Yadav

Deadlock and Deadlock Types in SQL Server

Hello All, Deadlock in SQL Server: Deadlock is a situation where two or more transactions wait for completion of each-other for resources but none of them completes. In SQL Server, deadlock-detractor thread monitors the deadlock situation. Once the situation  occurs, SQL Server rollback  the transaction which is less expensive with error message " Aborted Transaction error message 1205 " and roll-forward the transaction which is more expensive compare to the other one. Types of Deadlocks in SQL Server:  In SQL Server, there are 6 types of deadlocks are there... 1. Read-Write Deadlock 2. Write-Write Deadlock 3. Parallelism Deadlock 4. Key Lookup Deadlock 5. Rang-scans and Serializable Deadlock 6. Partition Escalation Deadlock

SQL Server 2008 R2 IA64 and x64.

MS has released SQL Server 2008 R2 for 64 bit architecture in two avatar x64 and IA64. x64 is the general 64-bit architecture, but Intel developed an alternative architecture known as IA64 Itanium Processors.   It was designed as a high-end alternative to mainframes, but the platform didn’t have very many production implementations of SQL Server and has subsequently been dropped from SQL Server 2012.  Windows has also dropped support for IA64 with the release of Windows Server 2012, which runs only on x64.