A key bit of information is missing (no pun intended) - how are the tables related? Does each table have a single column "ordernumber"?
Assuming that all the files are linked by an "ordernumber" in each table, then there are the following types of data relationship problems which could exist:
1. OrderInfo with no DeliveryInfo associated
select orderid from orderinfo oi
where not exists (select 1 from deliveryinfo di where di.ordernumber = oi.ordernumber);
2. OrderInfo with no ItemLines associated
select orderid from orderinfo oi
where not exists (select 1 from itemline il where il.ordernumber = oi.ordernumber);
3. DeliveryInfo with no ItemLines associated
select deliveryid from deliveryinfo di
where not exists (select 1 from itemlines il where il.ordernumber = di.ordernumber);
4. DeliveryInfo with an OrderNumber which doesn't match any OrderInfo record
select deliveryid from deliveryinfo di
where not exists (select 1 from orderinfo oi where oi.ordernumber = di.ordernumber);
5. ItemLines with an OrderNumber which doesn't match any OrderInfo record
select itemid from itemlines il
where not exists (select 1 from orderinfo oi where oi.ordernumber = il.ordernumber)
There can also be itemlines records with ordernumbers that don't match deliveryinfo records, but that set would be a subset of the records already found above.
Doing one giant query that finds all the broken links would be a challenge, and probably cause lots of table scans.
If you have some nice unique indexes on the tables, like:
create unique index oin on OrderInfo(ordernumber, orderid);
create unique index din on DeliveryInfo(ordernumber, deliveryid);
create unique index iln on ItemLines(ordernumber, itemid);
then the queries will be relatively efficient. (This assumes you have some column, or small set of columns that is a primary key that can be used for the "orderid", "deliveryid", and "itemid" columns, respectively.)
To see other answers submitted to the Answer Wiki
View Answer History.