Hi all
Lets say we have two tables:
Customer:
Customer_number : Decimal(15)
Name : Char(30)
Purchase:
Purchase_number : Decimal(15)
Customer_number : Decimal(15)
There is a relationship between Purchase and Customer, so that each
purchase must belong to a customer. That is, Customer_number in the
Purchase table must match a row in the Customer table (with the same
customer_number) - a foreign key.
This relationship is not enforced by the database.
One day you discover, that not all purchases has a relationship to an
existing customer. That is, the database is inconsistent. First you make a
select to find the inconsistent rows:
select *
from Purchase p
left outer join Customer c
on p.customer_number = c.customer_number
where c.customer_number is null
Lets say, you find 20 similar unenforced relationships (between other
tables). All containing inconsistent rows. You make 20 select statements
to discover all the inconsistencies.
The next step is to delete the inconsistencies. And this is my question.
How do one safely (be sure to only delete inconsistent rows) and easily
delete the inconsistencies? It is a requirement, that one would be able to
see which rows has been deleted. You have a typical IBM MVS/TSO
environment at your disposal. That is DB2, COBOL, JCL, Spufi, QMF, ...
Greetings,
Mads