Can a where Clause be used along with a Truncate command

[1391 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.

        

Algorithm Logic Test

Our Quiz prepared by Experts Helps you identify your knowledge in Algorithms. Everyone should atleast attempt this Quiz Once. 



Need any help in Programming? Chat with Us

Comments



Online Compiler
Search
Algorithm Quiz

Only 5% Users were able to score above 75% in this Quiz. Can You Crack this?

Deals Ends in





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

Search Tags