| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> comp.databases.theory -> Re: Conditional Relationships ?
perhaps I should have Posted Erland's solution in full.
Quote:
CONSTRAINT ckt_invint_orderref CHECK (
Order IS NULL AND Order_item IS NOT NULL OR
Order IS NOT NULL AND Order_item IS NULL)
And the regular foreign-key constraints to the Orders and Order_items table.
While at i'ts simplest this does not appear to prevent separate Invoices being raised for the Order alone , and then for Order items of that order if you use an Order_ID and the Order_Items_ID - as you point out - , the method can be applied by using additional Checks
So:
CONSTRAINT ckt_invint_orderref CHECK (
( Invoice.Order_ID IS NOT NULL
AND
Invoice.Order_Items_ID IS NULL
AND
Invoice.Order_ID NOT IN
( SELECT invoice.order_id
FROM invoice
WHERE invoice.cancelled = 0 ))
OR
( Invoice.Order_ID IS NOT NULL
AND
Invoice.Order_Items_ID IS NOT NULL
AND
Invoice.Order_ID NOT IN
( SELECT invoice.order_id
FROM invoice
WHERE invoice.cancelled = 0
AND invoice.order_items_id IS NULL ))
)
Note: this is Air-Code and I haven't checked this yet.
H.
"Neil Burnett" <neil_at_efc.be> wrote in message
news:ea0243b5.0212310740.20f1e76d_at_posting.google.com...
> I can't see how this solves your problem. It is still possible to have
> an invoice for a full order existing as well as an invoice for order
> items off that order:
>
>
>
--- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.431 / Virus Database: 242 - Release Date: 17-Dec-2002Received on Tue Dec 31 2002 - 20:44:15 CST
![]() |
![]() |