Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 304935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:19:35+00:00 2026-05-12T07:19:35+00:00

Is it bad practice to use triggers or scripts to maintain data integrity that

  • 0

Is it bad practice to use triggers or scripts to maintain data integrity that Oracle is not designed to enforce, or is this a sign I’m modeling my data in a poor way?

From responses to a previous post (Implementing User Defined Fields), I have decided that I want to move forward designing with a mix of Class and Concrete Inheritance. I want one base class for all SAMPLE then a concrete table for each unique set of attributes.

While I can enforce that each concrete table has a parent entry in SAMPLE by making SAMPLE.sample_id the primary key with a foreign key constraint. However, I do not know how to enforce that a SAMPLE entry has exactly one child since the child entry could be in any number of tables.

How can I enforce this? If the solution is INSERT, UPDATE, and DELETE triggers, is this considered bad-practice?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T07:19:36+00:00Added an answer on May 12, 2026 at 7:19 am

    I think you can solve this by using a materialized view that is a union all of TABLEA, TABLEB and TABLEC + groub by on master table id. You have to create a materialized view logs to make this a fast refreshable materialize view. And you have add a check constraint that throws an error when there is more than row in the materialized view per master table id.

    Rob van Wijk explains here http://rwijk.blogspot.com/2009/07/fast-refreshable-materialized-view.html a lot about fast refresible mv’s. Rob van Wijk is often present here at stackoverflow too.

    Here you can read on the use of check constraints on materialized views: http://technology.amis.nl/blog/475/introducing-materialized-views-as-mechanism-for-business-rule-implementation-complex-declarative-constraints

    Using fast refresizable mv’s means that the integrity check is done during committing, not during the inserting or updateting of data.

    I’m a very tired I can’t test it myself and I can’t provide a real example.

    edit1: Here is the example:

    It works when you create a fast refresh mv with a check constraint and a unique function based index.

    First we create the tables:

    SQL> create table mastertable (id number(10) not null primary key);
    
    SQL> create table tablea
    (id number(10) not null primary key
    , master_id number(10) not null references mastertable (id));
    
    SQL> create table tableb
    (id number(10) not null primary key
    , master_id number(10) not null references mastertable (id));
    
    SQL> create table tablec
    (id number(10) not null primary key
    , master_id number(10) not null references mastertable (id));
    

    Then we create the mv logs:

    SQL> create materialized view log on tablea with rowid (master_id) 
         including new values;
    
    SQL> create materialized view log on tableb with rowid (master_id) 
         including new values;
    
    SQL> create materialized view log on tablec with rowid (master_id) 
         including new values;
    

    The mv (the umarker column is really needed!):

    SQL> create materialized view table_abc
         refresh fast with rowid on commit
         as
         select master_id,count(*) master_count, 'A' umarker
         from   tablea
         group by master_id
         union all
         select master_id,count(*) master_count, 'B' umarker
         from   tableb
         group by master_id
         union all
         select master_id,count(*) master_count, 'C' umarker
         from   tablec
         group by master_id
         /
    

    Now we add a check constraint to this mv to ensure that you can’t insert twice in the same detail table per master_id:

    SQL> alter table table_abc add check (master_count in (0,1) );
    

    And we add a unique function based index to this mv to ensure that you can’t insert in table a and table b with the same master_id:

    SQL> create unique index table_abc_ufbi1 on table_abc
         (case when master_count = 1 then master_id else null end);
    

    Test 1 (the happy path):

    SQL> insert into mastertable values (1);

    1 rij is aangemaakt.

    SQL> insert into tablea values (1,1);

    1 rij is aangemaakt.

    SQL> commit;

    Commit is voltooid.

    Test 2 (one insert in table a and one insert in table b with same master_id)

    SQL> insert into mastertable values (2);

    1 rij is aangemaakt.

    SQL> insert into tablea values (2,2);

    1 rij is aangemaakt.

    SQL> insert into tableb values (3,2);

    1 rij is aangemaakt.

    SQL> commit;
    commit
    *
    FOUT in regel 1:
    .ORA-12008: Fout in pad voor vernieuwen van snapshot.
    ORA-00001: Schending van UNIQUE-beperking (TESTT.TABLE_ABC_UFBI1).

    test 3 (insert in table a twice with same master_id)

    SQL> insert into mastertable values (3);

    1 rij is aangemaakt.

    SQL> insert into tablea values (4,3);

    1 rij is aangemaakt.

    SQL> insert into tablea values (5,3);

    1 rij is aangemaakt.

    SQL> commit;
    commit
    *
    FOUT in regel 1:
    .ORA-12008: Fout in pad voor vernieuwen van snapshot.
    ORA-02290: CHECK-beperking (TESTT.SYS_C0015406) is geschonden.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 198k
  • Answers 198k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Overlaps are relatively easy (but you might have to worry… May 12, 2026 at 7:38 pm
  • Editorial Team
    Editorial Team added an answer There are column-oriented databases that store data on a per-column… May 12, 2026 at 7:38 pm
  • Editorial Team
    Editorial Team added an answer There is no such command/option in Eclipse and it might… May 12, 2026 at 7:38 pm

Related Questions

I've been working with some event handling in Javascript and recently decided to migrate
What are good ways to handle user input concurrency? As the answers to this
Is it bad practice to use the following format when my_var can be None?
Is it bad practice to use the generated objects from Entity Framework as business

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.