The DELETE statement delete rows from a table.
DELETE FROM table_name WHERE condition; |
Note: If there is no “where” clause in the Delete statement, then SQL will delete all the data in the table. So you need to be very careful while executing the Delete statement and make sure that there is a Where clause.
Below is a selection from the "Product" table in the DB2 database:
ProductID | ProductDesc | Category | SRP | QtyOnHand | TotalValue |
---|---|---|---|---|---|
7001 | Mouse | Accessories | 75.00 | ||
7002 | Harddrive | 65.00 | 20 | 1,300 | |
7003 | Keyboard | Accessories | 36.00 | 33 | 1,118.00 |
7004 | Ram | Components | 23.50 | 16 | 376.00 |
7005 | Honda | Bikes | 1,200 | ||
7006 | Pen | 7.45 | 10 | 74.50 |
Delete 'ProductID' 7003 from 'Product' table.
DELETE FROM Product WHERE ProductID = ‘7003’; |
ProductID | ProductDesc | Category | SRP | QtyOnHand | TotalValue |
---|---|---|---|---|---|
7001 | Mouse | Accessories | 75.00 | ||
7002 | Harddrive | 65.00 | 20 | 1,300 | |
7004 | Ram | Components | 23.50 | 16 | 376.00 |
7005 | Honda | Bikes | 1,200 | ||
7006 | Pen | 7.45 | 10 | 74.50 |
Delete all the departments from 'Product' table (that is, empty the table).
The following SQL statement deletes all rows in the "Product" table, without deleting the table.
DELETE FROM Product; |
Empty table
ProductID | ProductDesc | Category | SRP | QtyOnHand | TotalValue |
---|
If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!