SQL DELETE ROW
The SQL DELETE ROW operation removes specific rows from a table based on a condition. This is particularly useful when you want to delete erroneous or obsolete data while keeping the rest of the table intact.
The WHERE clause in the DELETE statement ensures only the targeted rows are removed.
Example
This example removes the row where the product is "Tablet".
Code Example
-- Delete the row where the product is 'Tablet'
DELETE FROM Orders
WHERE Product = 'Tablet';
-- View the updated table
SELECT * FROM Orders;
Output
Product | Category | Price |
---|---|---|
Laptop | Electronics | 1300.00 |
Phone | Mobile Devices | 800.00 |
Smartwatch | Gadgets | 250.00 |
Headphones | Gadgets | 150.00 |
Explanation
- The DELETE statement targets the row with the condition Product = 'Tablet'.
- Only the row matching the condition is removed.
- The updated table no longer includes the "Tablet" row, while other rows remain unaffected.