SQL TRUNCATE Statement

The SQL TRUNCATE statement is used to remove all data from a table, including all rows, indexes, and constraints. Unlike the DELETE statement, the TRUNCATE statement is much faster and more efficient for removing all data from a table.

Orders Table:

OrderIDCustomerID
110
220
330

To remove all data from the Orders table, we can use the following TRUNCATE statement:

1TRUNCATE TABLE Orders;

The output of the above query will be an empty Orders table:

all rows deleted in Orders Table:

OrderIDCustomerID

As we can see, the TRUNCATE statement removes all data from the Orders table. It's important to note that TRUNCATE is a more efficient way to remove all data from a table compared to the DELETE statement, as it resets the high-water mark and reclaims disk space immediately.

It's important to note that TRUNCATE operations drop and re-create the table, which is much faster than deleting rows one by one, particularly for large tables. However, like DELETE, TRUNCATE operations are also permanent and the data cannot be recovered once it is removed.