Can a where Clause be used along with a Truncate command

[1510 views]


Every SQL Developer wants full control over the Database by query. Due to which they start thinking beyond the SQL syntax. One such misconception is whether a where Clause be used along with a Truncate command to perform some conditional operations.

For example, if someone wants to delete all records of last week (7 days) using Truncate command. Although this can be done using "Delete from table_name where conditions" but truncate is used because it is faster than Delete query.

The Answer for the question "Can a where Clause be used along with a Truncate command" is NO. Truncate statement means All or Nothing. This means either all the records in the Table will be deleted or none of them will be deleted.

What does TRUNCATE TABLE mean?

TRUNCATE TABLE is a statement in SQL that deletes all records in a table very fast by deallocating the data pages used by the table. Deallocating the data pages reduces the resource overhead of logging the deletions done, as well as the number of locks acquired. Records removed by the TRUNCATE TABLE query statement cannot be restored, so you need to be very careful before executing TRUNCATE TABLE query.

        

Struggling to Understand Algorithm and Flowchart? Try our Notes



Want to Test Your Knowledge on Algorithm and Flowchart?



Comments



Recommended Deals End in



Search
Online Games
Play 2048 Game Online and Relax.
Play 2048 Game Online

Search Tags