What is Use TRUNCATE TABLE to remove all rows

DELETE without a WHERE clause removes all the rows from a table. For this reason, DELETE is usually used conditionally, with a filter in the WHERE clause. If you really do want to remove all the rows and leave an empty table, you can use the TRUNCATE TABLE statement. This statement does not allow a WHERE clause and always removes all the rows in one operation. Here’s an example:

SQLCopy

TRUNCATE TABLE Sales.Sample;

TRUNCATE TABLE is more efficient than DELETE when you do want to remove all rows.

Leave a Reply

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