Subject Re: preventing orphaned rows
Author dtrudgett
Duilio Foschi wrote:

> I have a master table and a detail table.
>
> I want to prevent (at the DB level)
>
> 1. that a master record is inserted with no detail record
> 2. that a detail record is inserted with no master record

Have you thought of inserting a detail row from within an AFTER INSERT
trigger on the master table? Alternatively, insert both the master row
and the first detail row using a stored procedure that first does the
master, then the detail.

Similarly, you could use a BEFORE DELETE trigger on the detail table
to make sure at least one detail row remains for the master row.

Come va il progetto?

David Trudgett