Sobes.tech
Junior — Middle

Which command executes faster when clearing a table in a database — TRUNCATE or DELETE?

sobes.tech AI

Answer from AI

The TRUNCATE command is usually faster than DELETE when clearing an entire table. This is because TRUNCATE does not delete rows one by one but simply resets the table data, freeing data pages and resetting counters, which is much faster. Meanwhile, DELETE removes rows one by one, which can be slower, especially with large amounts of data, and generates more transaction logs. However, DELETE allows the use of WHERE conditions and triggers, whereas TRUNCATE does not.