TSO-ISPF JCL COBOL VSAM DB2 CICS Tools Articles Job Portal Forum Quiz Interview Q&A

DB2 - SQL Delete Statement


The DELETE statement delete rows from a table.

Syntax:

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.

DB2 Database:

Below is a selection from the "Product" table in the DB2 database:

ProductIDProductDescCategorySRPQtyOnHandTotalValue
7001MouseAccessories75.00
7002Harddrive65.00201,300
7003KeyboardAccessories36.00331,118.00
7004RamComponents23.5016376.00
7005HondaBikes1,200
7006Pen7.451074.50

Example 1: Delete One Record

Delete 'ProductID' 7003 from 'Product' table.

DELETE FROM Product WHERE ProductID = ‘7003’;
Result:
ProductIDProductDescCategorySRPQtyOnHandTotalValue
7001MouseAccessories75.00
7002Harddrive65.00201,300
7004RamComponents23.5016376.00
7005HondaBikes1,200
7006Pen7.451074.50


Example 2: Delete All Records

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;
Result:

Empty table

ProductIDProductDescCategorySRPQtyOnHandTotalValue


If you have any doubts or queries related to this chapter, get them clarified from our Mainframe experts on ibmmainframer Community!

Are you looking for Job Change? Job Portal