SQL TRUNCATE TABLE Command vs DELETE

T-SQL TRUNCATE command deletes all records in the table. Apart from DELETE (more in article SQL DELETE) command, there is no possibility to filter which record to delete. It is all or nothing. Truncate is on the other hand much faster compared to DELETE since it writes less into transaction log.

SQL TRUNCATE command Syntax

TRUNCATE TABLE dbo.Table;

or

TRUNCATE dbo.Table;

First possibility is optional. When processing this command, table gets basically deleted (DROP TABLE) and created again (CREATE TABLE) without putting load on transaction log. More on truncate on Microsoft web

Rate this post
Category: Handling SQL tables

About Ing. Jan Zedníček - Data Engineer & Controlling

My name is Jan Zednicek, and I have been working as a freelance Data Engineer for roughly 10 years. During this time, I have been publishing case studies and technical guides on this website, targeting professionals, students, and enthusiasts interested in Data Engineering particularly on Microsoft technologies as well as corporate finance and reporting solutions. 🔥 If you found this article helpful, please share it or mention me on your website or Community forum

Leave a Reply

Your email address will not be published. Required fields are marked *