self-referential integrity?
Posted in 1997
Topics: Triggers, Constraints & Referential Integrity
I have two tables and I want to identify (and then delete) rows from the
subordinate table that does not have a match in the primary table.
eg.
Customers (cust_code char(4), name char(20))
Orders (cust_code char(4), ord_date date, etc etc))
So, if a Customer has been deleted, how can I identify (prior to deleting)
the orders that do not have a customer record?
delete from orders where
where orders.cust_code 'does not match any records in the Customer table'
This is a simplistic version of events, inactuality my database has about
seven levels of lookup; Contracts=>Customers=>Contacts=>Orders=>Order_Lines
etc etc
I guess what I should be doing is setting up some form of ref. integrity but
1) I don't know how to and
2) I don't know how to
I realise that (1) and (2) are the same but I thought that (1) was so
important it was worth mentioning twice.
ps. I a using Inf 5SE (could be using 7.23SE with a struggle).
Mark Webb