SQL DELETE ALL ROWS

The SQL DELETE ALL ROWS operation removes all rows from a table while leaving the table's structure intact. This is useful when you want to clear out a table's data without deleting the table itself. While similar to the TRUNCATE statement, the DELETE command provides more control, as you can use conditions to limit which rows are deleted, even when targeting all rows.

When using DELETE without a WHERE clause, the operation will remove all rows from the table. However, you may notice slower performance compared to TRUNCATE, as DELETE logs each row removal.

Example

This example demonstrates removing all rows from the Orders table.

Code Example


-- Delete all rows from the Orders table
DELETE FROM Orders;

-- View the table structure after deletion
SELECT * FROM Orders;
            

Output

Product Category Price
No rows found

Explanation

- The DELETE statement without a WHERE clause removes all rows.
- The table structure remains intact for future use.
- Unlike DROP, the table definition is preserved, allowing for new rows to be added later.