Re: enforce no master without detail
From: Phil Herring <phil_herring_at_yahoo.com.au>
Date: Wed, 5 Aug 2009 03:04:03 -0700 (PDT)
Message-ID: <908939f6-7d32-4982-bef6-189ed67eeca1_at_d4g2000prc.googlegroups.com>
It helps if you say which version of Oracle you're using.
Date: Wed, 5 Aug 2009 03:04:03 -0700 (PDT)
Message-ID: <908939f6-7d32-4982-bef6-189ed67eeca1_at_d4g2000prc.googlegroups.com>
It helps if you say which version of Oracle you're using.
One possible solution for 10g and 9i:
- Numeric "child counter" column on the parent.
- Insert and delete triggers on the child that increment and decrement (respectively) the child counter.
- A deferred check constraint on the parent that specifies that the child counter > 0.
A possible (equivalent) solution for 11g:
- A deterministic function that counts the rows in the child table.
- A virtual column on the parent that calls the function to count the children.
- A deferred check constraint on the parent that specifies the
virtual column > 0.
- Phil