Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Do you use Oracle? </p> <p>If you use Oracle you can validate the data in a declarative way with the use of a fast refresh materialized view, you have to add a check constraint to this materialized view. This means that the validation will be done when a commit is happening. </p> <p><strong>Edit1</strong></p> <p>It saddens me a little that oo didn't anwer my imho really very simple question, so I don't know whether or not he/she uses Oracle, but anyway:</p> <p>Let's create a table with a materialized view log, a materialized view with a group by on resourceid and a check constraint to check that the sum of PctOfTime equals 100 for every resourceid. </p> <pre><code>create table applicationresources ( id number(10) not null primary key, applicationid number(10) not null, resourceid number(10) not null, pctoftime number(3) not null ); create materialized view log on applicationresources with rowid (id,applicationid,resourceid,pctoftime) including new values; create materialized view pctoftimecheck refresh fast on commit as select sum(pctoftime) sum_time,resourceid from applicationresources group by resourceid / alter table pctoftimecheck add constraint c1 check(sum_time=100); </code></pre> <p>Now two examples:</p> <p>Example1 (will succeed):</p> <pre><code>insert into applicationresources values (1, 1, 1, 50); insert into applicationresources values (2, 2, 1, 50); commit; </code></pre> <p>Example2 (will fail on commit because sum=101)</p> <pre><code>insert into applicationresources values (3, 1, 2, 50); insert into applicationresources values (4, 2, 2, 50); insert into applicationresources values (5, 3, 2, 1); commit; SQL&gt; Error: ORA-02290: CHECK-constraint (DSEDD.C1) violated. </code></pre> <p>See for more info: <a href="http://rwijk.blogspot.com/2009/06/fast-refreshable-materialized-view.html" rel="nofollow noreferrer">http://rwijk.blogspot.com/2009/06/fast-refreshable-materialized-view.html</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload