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.
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
all rows deleted in Orders Table:
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.