SQL DELETE TABLE
The SQL DELETE TABLE operation removes all rows from a table while keeping the table structure intact. This is achieved using the DELETE statement without a WHERE clause. It is similar to TRUNCATE, but with some differences in execution.
Use this operation when you want to retain the table for future data but remove its contents completely.
Example
This example removes all data from the Orders table.
Code Example
-- Delete all rows from the Orders table
DELETE FROM Orders;
-- View the empty table
SELECT * FROM Orders;
Output
Product | Category | Price |
---|---|---|
No rows found |
Explanation
- The DELETE statement removes all rows from the Orders table.
- Unlike the DROP command, the table structure remains intact and can still be used for future data insertion.
- After execution, the table appears empty.