Subject RE: [firebird-support] Triggers and referential integrity
Author Salim Naufal
Tim, here is an example:

Create table taxes
( PKEY integer not null,
rate double precision,
Primary key(PKEY) )

Create table Sales
( PKEY integer not null,
taxe_code integer,
...)

Create exception cannot_delete_tax 'cannot delete tax'

Create trigger bd_taxes for taxes
Active before delete
As
Begin
if (exists(select PKEY from Sales where taxe_code = old.PKEY)) then
begin
exception cannot_delete_tax;
end

end

Hope that helps

Salim
-----Original Message-----
From: Tim Ledgerwood [mailto:tim@...]
Sent: Tuesday, October 21, 2003 10:43 AM

Hi Martijn,

:-) I already make extensive use of domains with check constraints - the
primary table has every field except the primary key field as a domain with
a check constraint.

As I said, the problem isn't the Inserts so much as the deletes. In the
case of a tax table (we also have three here), how do I prevent the user
from deleting a tax type if there are any records in the primary table with
that tax type?

Regards

Tim