Oracle 使用触发器维护引用完整性

Oracle 使用触发器维护引用完整性,oracle,plsql,database-trigger,referential-integrity,Oracle,Plsql,Database Trigger,Referential Integrity,我正在尝试为关系部分的任何插入编写SQL触发器,它应该确保插入的时隙id值有效 提前谢谢 让我们首先说明,使用触发器强制执行关系完整性而不是外键约束是最糟糕的做法。RI触发器很慢,不能很好地扩展,不能在多用户环境中工作,它们会在那些不得不维护代码的可怜虫中引起不必要的挠头 因此,这就是运行最差实践触发器的样子: create or replace trigger section_timeslot_trg before insert or update on section for each

我正在尝试为关系
部分的任何插入编写SQL触发器,它应该确保插入的时隙id值有效


提前谢谢

让我们首先说明,使用触发器强制执行关系完整性而不是外键约束是最糟糕的做法。RI触发器很慢,不能很好地扩展,不能在多用户环境中工作,它们会在那些不得不维护代码的可怜虫中引起不必要的挠头

因此,这就是运行最差实践触发器的样子:

create or replace trigger section_timeslot_trg 
before insert or update on section
for each row
declare
    l_id timeslot.timeslot_id%type;
begin
    select ts.timeslot_id
    into l_id
    from timeslot ts
    where ts.timeslot_id = :new.timeslot_id;
exception
    when no_data_found then
        raise_application_error(-20999, 'Not a valid TIMESLOT_ID: '||:new.timeslot_id);
end;

请记住,在没有外键约束的情况下,需要在时隙上有一个反向触发器,以防止更新和删除第节中使用的时隙ID

我想知道如何编写这样的触发器。我正在使用Oracle。请不要使用图像发布重要的细节,如表结构或示例数据。许多人躲在防火墙后面,防火墙阻止了对图像转储的访问。此外,当涉及到重新创建问题和确保建议的解决方案编译和工作时,这也是非常不方便的。